From ae2a01da2e388535da243b3d974aef74a3c06ae0 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 9 Apr 2018 12:33:17 -0400 Subject: fix wrong result in casin and many related complex functions the factor of -i noted in the comment at the top of casin.c was omitted from the actual code, yielding a result rotated 90 degrees and propagating into errors in other functions defined in terms of casin. implement multiplication by -i as a rotation of the real and imaginary parts of the result, rather than by actual multiplication, since the latter cannot be optimized without knowledge that the operand is finite. here, the rotation is the actual intent, anyway. --- src/complex/casin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/complex/casin.c') diff --git a/src/complex/casin.c b/src/complex/casin.c index dfdda988..01ed6184 100644 --- a/src/complex/casin.c +++ b/src/complex/casin.c @@ -12,5 +12,6 @@ double complex casin(double complex z) x = creal(z); y = cimag(z); w = CMPLX(1.0 - (x - y)*(x + y), -2.0*x*y); - return clog(CMPLX(-y, x) + csqrt(w)); + double complex r = clog(CMPLX(-y, x) + csqrt(w)); + return CMPLX(cimag(r), -creal(r)); } -- cgit v1.2.1