fix cacosh results for arguments with negative imaginary part
authorMichael Morrell <mmorrell@tachyum.com>
Mon, 14 Oct 2019 13:07:31 +0000 (09:07 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 14 Oct 2019 13:08:22 +0000 (09:08 -0400)
src/complex/cacosh.c
src/complex/cacoshf.c
src/complex/cacoshl.c

index 8e42f1a..76127f7 100644 (file)
@@ -4,6 +4,9 @@
 
 double complex cacosh(double complex z)
 {
+       int zineg = signbit(cimag(z));
+
        z = cacos(z);
-       return CMPLX(-cimag(z), creal(z));
+       if (zineg) return CMPLX(cimag(z), -creal(z));
+       else       return CMPLX(-cimag(z), creal(z));
 }
index d7e6b54..8bd8058 100644 (file)
@@ -2,6 +2,9 @@
 
 float complex cacoshf(float complex z)
 {
+       int zineg = signbit(cimagf(z));
+
        z = cacosf(z);
-       return CMPLXF(-cimagf(z), crealf(z));
+       if (zineg) return CMPLXF(cimagf(z), -crealf(z));
+       else       return CMPLXF(-cimagf(z), crealf(z));
 }
index d3eaee2..3a284be 100644 (file)
@@ -8,7 +8,10 @@ long double complex cacoshl(long double complex z)
 #else
 long double complex cacoshl(long double complex z)
 {
+       int zineg = signbit(cimagl(z));
+
        z = cacosl(z);
-       return CMPLXL(-cimagl(z), creall(z));
+       if (zineg) return CMPLXL(cimagl(z), -creall(z));
+       else       return CMPLXL(-cimagl(z), creall(z));
 }
 #endif