瀏覽代碼

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.
Rich Felker 7 年之前
父節點
當前提交
ae2a01da2e
共有 3 個文件被更改,包括 6 次插入3 次删除
  1. 2 1
      src/complex/casin.c
  2. 2 1
      src/complex/casinf.c
  3. 2 1
      src/complex/casinl.c

+ 2 - 1
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));
 }

+ 2 - 1
src/complex/casinf.c

@@ -10,5 +10,6 @@ float complex casinf(float complex z)
 	x = crealf(z);
 	y = cimagf(z);
 	w = CMPLXF(1.0 - (x - y)*(x + y), -2.0*x*y);
-	return clogf(CMPLXF(-y, x) + csqrtf(w));
+	float complex r = clogf(CMPLXF(-y, x) + csqrtf(w));
+	return CMPLXF(cimagf(r), -crealf(r));
 }

+ 2 - 1
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