# HG changeset patch # User Bruno Haible # Date 1320603427 -3600 # Node ID e2ff993ff145475bccabcc29e1b19119366a8625 # Parent 843e85c128309d0aede08428c65e6b098453ce7e copysignl: Fix result for zero argument on HP-UX 11 with HP C. * lib/copysignl.c (compute_minus_zerol) [HP-UX]: New function. (minus_zerol) [HP-UX]: New macro. (unary_minus) [HP-UX]: New function. (copysignl) [HP-UX]: Use unary_minus function. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-11-06 Bruno Haible + + copysignl: Fix result for zero argument on HP-UX 11 with HP C. + * lib/copysignl.c (compute_minus_zerol) [HP-UX]: New function. + (minus_zerol) [HP-UX]: New macro. + (unary_minus) [HP-UX]: New function. + (copysignl) [HP-UX]: Use unary_minus function. + 2011-11-06 Bruno Haible ldexp, ldexpf, ldexpl: Enhance tests. diff --git a/lib/copysignl.c b/lib/copysignl.c --- a/lib/copysignl.c +++ b/lib/copysignl.c @@ -29,10 +29,44 @@ #else +# if defined __hpux && !defined __GNUC__ + +# include + +/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0L. */ +static long double +compute_minus_zerol (void) +{ + return -LDBL_MIN * LDBL_MIN; +} +# define minus_zerol compute_minus_zerol () + +/* HP cc on HP-UX 11 has a bug: When x is a positive zero, - x comes out + as a positive zero, rather than as a minus zero. Work around it. */ +static long double +unary_minus (long double x) +{ + if (x == 0.0L) + { + if (signbit (x)) + return 0.0L; + else + return minus_zerol; + } + else + return - x; +} + +# endif + long double copysignl (long double x, long double y) { +# if defined __hpux && !defined __GNUC__ + return (signbit (x) != signbit (y) ? unary_minus (x) : x); +# else return (signbit (x) != signbit (y) ? - x : x); +# endif } #endif