fix potentially wrong-sign zero in cproj functions at infinity
authorRich Felker <dalias@aerifal.cx>
Tue, 18 Jan 2022 22:31:46 +0000 (17:31 -0500)
committerRich Felker <dalias@aerifal.cx>
Tue, 18 Jan 2022 22:31:46 +0000 (17:31 -0500)
these are specified to use the sign of the imaginary part of the input
as the sign of zero in the result, but wrongly copied the sign of the
real part.

src/complex/cproj.c
src/complex/cprojf.c
src/complex/cprojl.c

index 9ae1e17..d2b8f5a 100644 (file)
@@ -3,6 +3,6 @@
 double complex cproj(double complex z)
 {
        if (isinf(creal(z)) || isinf(cimag(z)))
-               return CMPLX(INFINITY, copysign(0.0, creal(z)));
+               return CMPLX(INFINITY, copysign(0.0, cimag(z)));
        return z;
 }
index 03fab33..15a874b 100644 (file)
@@ -3,6 +3,6 @@
 float complex cprojf(float complex z)
 {
        if (isinf(crealf(z)) || isinf(cimagf(z)))
-               return CMPLXF(INFINITY, copysignf(0.0, crealf(z)));
+               return CMPLXF(INFINITY, copysignf(0.0, cimagf(z)));
        return z;
 }
index 38a494c..531ffa1 100644 (file)
@@ -9,7 +9,7 @@ long double complex cprojl(long double complex z)
 long double complex cprojl(long double complex z)
 {
        if (isinf(creall(z)) || isinf(cimagl(z)))
-               return CMPLXL(INFINITY, copysignl(0.0, creall(z)));
+               return CMPLXL(INFINITY, copysignl(0.0, cimagl(z)));
        return z;
 }
 #endif