about summary refs log tree commit diff
path: root/src/complex/casinl.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-04-09 12:33:17 -0400
committerRich Felker <dalias@aerifal.cx>2018-04-09 13:25:35 -0400
commitae2a01da2e388535da243b3d974aef74a3c06ae0 (patch)
tree2ab4469ed5f3989c385b3dc50c58199f9affb593 /src/complex/casinl.c
parentea81529fb92932a50f06bf7a19cae812ae6cdb59 (diff)
downloadmusl-ae2a01da2e388535da243b3d974aef74a3c06ae0.tar.gz
musl-ae2a01da2e388535da243b3d974aef74a3c06ae0.tar.xz
musl-ae2a01da2e388535da243b3d974aef74a3c06ae0.zip
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.
Diffstat (limited to 'src/complex/casinl.c')
-rw-r--r--src/complex/casinl.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/complex/casinl.c b/src/complex/casinl.c
index 0916c60f..3b7ceba7 100644
--- a/src/complex/casinl.c
+++ b/src/complex/casinl.c
@@ -15,6 +15,7 @@ long double complex casinl(long double complex z)
 	x = creall(z);
 	y = cimagl(z);
 	w = CMPLXL(1.0 - (x - y)*(x + y), -2.0*x*y);
-	return clogl(CMPLXL(-y, x) + csqrtl(w));
+	long double complex r = clogl(CMPLXL(-y, x) + csqrtl(w));
+	return CMPLXL(cimagl(r), -creall(r));
 }
 #endif