1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Fix csqrt spurious underflows (bug 18371).

The csqrt implementations in glibc can cause spurious underflows in
some cases as a side-effect of the scaling for large arguments (when
underflow is correct for the square root of the argument that was
scaled down to avoid overflow, but not for the original argument).
This patch arranges to avoid the underflowing intermediate computation
(eliminating a multiplication in 0.5 in the problem cases where a
subsequent scaling by 2 would follow).

Tested for x86_64 and x86 and ulps updated accordingly (only needed
for x86).

	[BZ #18371]
	* math/s_csqrt.c (__csqrt): Avoid multiplication by 0.5 where
	intermediate but not final result might underflow.
	* 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.
This commit is contained in:
Joseph Myers
2015-06-23 16:01:54 +00:00
parent b59549574e
commit 718d34a309
8 changed files with 843 additions and 11 deletions

View File

@ -118,12 +118,28 @@ __csqrtl (__complex__ long double x)
if (__real__ x > 0)
{
r = __ieee754_sqrtl (0.5L * (d + __real__ x));
s = 0.5L * (__imag__ x / r);
if (scale == 1 && fabsl (__imag__ x) < 1.0L)
{
/* Avoid possible intermediate underflow. */
s = __imag__ x / r;
r = __scalbnl (r, scale);
scale = 0;
}
else
s = 0.5L * (__imag__ x / r);
}
else
{
s = __ieee754_sqrtl (0.5L * (d - __real__ x));
r = fabsl (0.5L * (__imag__ x / s));
if (scale == 1 && fabsl (__imag__ x) < 1.0L)
{
/* Avoid possible intermediate underflow. */
r = fabsl (__imag__ x / s);
s = __scalbnl (s, scale);
scale = 0;
}
else
r = fabsl (0.5L * (__imag__ x / s));
}
if (scale)