From aa2d23e57c9c95f0ffeb80cb035e5a5be52d8ef0 Mon Sep 17 00:00:00 2001 From: Michael Morrell Date: Mon, 14 Oct 2019 09:07:31 -0400 Subject: [PATCH] fix cacosh results for arguments with negative imaginary part --- src/complex/cacosh.c | 5 ++++- src/complex/cacoshf.c | 5 ++++- src/complex/cacoshl.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/complex/cacosh.c b/src/complex/cacosh.c index 8e42f1ae..76127f75 100644 --- a/src/complex/cacosh.c +++ b/src/complex/cacosh.c @@ -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)); } diff --git a/src/complex/cacoshf.c b/src/complex/cacoshf.c index d7e6b545..8bd80581 100644 --- a/src/complex/cacoshf.c +++ b/src/complex/cacoshf.c @@ -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)); } diff --git a/src/complex/cacoshl.c b/src/complex/cacoshl.c index d3eaee20..3a284be9 100644 --- a/src/complex/cacoshl.c +++ b/src/complex/cacoshl.c @@ -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 -- 2.25.1