about summary refs log tree commit diff
path: root/sysdeps/libm-ieee754
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/libm-ieee754')
-rw-r--r--sysdeps/libm-ieee754/s_csqrt.c10
-rw-r--r--sysdeps/libm-ieee754/s_csqrtf.c10
-rw-r--r--sysdeps/libm-ieee754/s_csqrtl.c10
3 files changed, 30 insertions, 0 deletions
diff --git a/sysdeps/libm-ieee754/s_csqrt.c b/sysdeps/libm-ieee754/s_csqrt.c
index c5c609bd8c..cda23c702d 100644
--- a/sysdeps/libm-ieee754/s_csqrt.c
+++ b/sysdeps/libm-ieee754/s_csqrt.c
@@ -84,6 +84,7 @@ __csqrt (__complex__ double x)
 	}
       else
 	{
+#if 0 /* FIXME: this is broken. */
 	  __complex__ double q;
 	  double t, r;
 
@@ -99,6 +100,15 @@ __csqrt (__complex__ double x)
 
 	  /* Heron iteration in complex arithmetic.  */
 	  res = 0.5 * (q + q / x);
+#else
+	  double d, imag;
+
+	  d = __ieee754_hypot (__real__ x, __imag__ x);
+	  imag = __ieee754_sqrt (0.5 * (d - __real__ x));
+
+	  __real__ res = __ieee754_sqrt (0.5 * (d + __real__ x));
+	  __imag__ res = __copysign (imag, __imag__ x);
+#endif
 	}
     }
 
diff --git a/sysdeps/libm-ieee754/s_csqrtf.c b/sysdeps/libm-ieee754/s_csqrtf.c
index 2289045cfd..5fdf2c1d66 100644
--- a/sysdeps/libm-ieee754/s_csqrtf.c
+++ b/sysdeps/libm-ieee754/s_csqrtf.c
@@ -84,6 +84,7 @@ __csqrtf (__complex__ float x)
 	}
       else
 	{
+#if 0 /* FIXME: this is broken. */
 	  __complex__ float q;
 	  float t, r;
 
@@ -99,6 +100,15 @@ __csqrtf (__complex__ float x)
 
 	  /* Heron iteration in complex arithmetic.  */
 	  res = 0.5 * (q + q / x);
+#else
+	  float d, imag;
+
+	  d = __ieee754_hypotf (__real__ x, __imag__ x);
+	  imag = __ieee754_sqrtf (0.5 * (d - __real__ x));
+
+	  __real__ res = __ieee754_sqrtf (0.5 * (d + __real__ x));
+	  __imag__ res = __copysignf (imag, __imag__ x);
+#endif
 	}
     }
 
diff --git a/sysdeps/libm-ieee754/s_csqrtl.c b/sysdeps/libm-ieee754/s_csqrtl.c
index 3de7310c73..b772709947 100644
--- a/sysdeps/libm-ieee754/s_csqrtl.c
+++ b/sysdeps/libm-ieee754/s_csqrtl.c
@@ -84,6 +84,7 @@ __csqrtl (__complex__ long double x)
 	}
       else
 	{
+#if 0 /* FIXME: this is broken. */
 	  __complex__ long double q;
 	  long double t, r;
 
@@ -99,6 +100,15 @@ __csqrtl (__complex__ long double x)
 
 	  /* Heron iteration in complex arithmetic.  */
 	  res = 0.5 * (q + q / x);
+#else
+	  long double d, imag;
+
+	  d = __ieee754_hypotl (__real__ x, __imag__ x);
+	  imag = __ieee754_sqrtl (0.5 * (d - __real__ x));
+
+	  __real__ res = __ieee754_sqrtl (0.5 * (d + __real__ x));
+	  __imag__ res = __copysignl (imag, __imag__ x);
+#endif
 	}
     }