This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fix csqrt missing underflows (bug 18370) [committed]
- From: Joseph Myers <joseph at codesourcery dot com>
- To: <libc-alpha at sourceware dot org>
- Date: Wed, 19 Aug 2015 22:42:34 +0000
- Subject: Fix csqrt missing underflows (bug 18370) [committed]
- Authentication-results: sourceware.org; auth=none
The csqrt implementations in glibc can miss underflow exceptions when
the real or imaginary part of the result becomes tiny in the course of
scaling down (in particular, multiplication by 0.5) and that scaling
is exact although the relevant part of the mathematical result isn't.
This patch forces the exception in a similar way to previous fixes.
Tested for x86_64 and x86. Committed.
(auto-libm-test-out diffs omitted below.)
2015-08-19 Joseph Myers <joseph@codesourcery.com>
[BZ #18370]
* math/s_csqrt.c (__csqrt): Force underflow exception for results
whose real or imaginary part has small absolute value.
* math/s_csqrtf.c (__csqrtf): Likewise.
* math/s_csqrtl.c (__csqrtl): Likewise.
* math/auto-libm-test-in: Add more tests of csqrt.
* math/auto-libm-test-out: Regenerated.
* sysdeps/i386/fpu/libm-test-ulps: Update.
diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index 015041a..49f1c55 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -1171,6 +1171,11 @@ csqrt 0x1p-16445 0x1.0000000000000004p-16382
csqrt 0x1p-16494 0x1.0000000000000000000000000001p-16382
csqrt 0x1p-16494 0x1.0000000000000000000000000002p-16382
+csqrt 1 min
+csqrt 1 -min
+csqrt -1 min
+csqrt -1 -min
+
ctan 0 0
ctan 0 -0
ctan -0 0
diff --git a/math/s_csqrt.c b/math/s_csqrt.c
index 068534c..b86f533 100644
--- a/math/s_csqrt.c
+++ b/math/s_csqrt.c
@@ -148,6 +148,17 @@ __csqrt (__complex__ double x)
s = __scalbn (s, scale);
}
+ if (fabs (r) < DBL_MIN)
+ {
+ double force_underflow = r * r;
+ math_force_eval (force_underflow);
+ }
+ if (fabs (s) < DBL_MIN)
+ {
+ double force_underflow = s * s;
+ math_force_eval (force_underflow);
+ }
+
__real__ res = r;
__imag__ res = __copysign (s, __imag__ x);
}
diff --git a/math/s_csqrtf.c b/math/s_csqrtf.c
index f7dc3b1..e433f47 100644
--- a/math/s_csqrtf.c
+++ b/math/s_csqrtf.c
@@ -148,6 +148,17 @@ __csqrtf (__complex__ float x)
s = __scalbnf (s, scale);
}
+ if (fabsf (r) < FLT_MIN)
+ {
+ float force_underflow = r * r;
+ math_force_eval (force_underflow);
+ }
+ if (fabsf (s) < FLT_MIN)
+ {
+ float force_underflow = s * s;
+ math_force_eval (force_underflow);
+ }
+
__real__ res = r;
__imag__ res = __copysignf (s, __imag__ x);
}
diff --git a/math/s_csqrtl.c b/math/s_csqrtl.c
index a0252e6..003d614 100644
--- a/math/s_csqrtl.c
+++ b/math/s_csqrtl.c
@@ -148,6 +148,17 @@ __csqrtl (__complex__ long double x)
s = __scalbnl (s, scale);
}
+ if (fabsl (r) < LDBL_MIN)
+ {
+ long double force_underflow = r * r;
+ math_force_eval (force_underflow);
+ }
+ if (fabsl (s) < LDBL_MIN)
+ {
+ long double force_underflow = s * s;
+ math_force_eval (force_underflow);
+ }
+
__real__ res = r;
__imag__ res = __copysignl (s, __imag__ x);
}
diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps
index 8263717..1cbf0db 100644
--- a/sysdeps/i386/fpu/libm-test-ulps
+++ b/sysdeps/i386/fpu/libm-test-ulps
@@ -1213,7 +1213,9 @@ ldouble: 2
Function: Real part of "csqrt_downward":
double: 1
+float: 1
idouble: 1
+ifloat: 1
ildouble: 4
ldouble: 4
@@ -1227,7 +1229,9 @@ ldouble: 4
Function: Real part of "csqrt_towardzero":
double: 1
+float: 1
idouble: 1
+ifloat: 1
ildouble: 4
ldouble: 4
--
Joseph S. Myers
joseph@codesourcery.com