mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-19 04:49:25 +08:00
sqrt: Fix NaN propagation for IEEE Std 754-2008
The R language has some hacks specifically for mingw-w64 that were caused by our handling of NaNs in sqrt(x). R uses a special valued NaN to mean 'Not Available' and expects it to be retained through various calculations. Our sqrt(x) doesn't do this, instead it normalises such a NaN (retaining sign). From: http://wwwf.imperial.ac.uk/~drmii/M3SC_2016/IEEE_2008_4610935.pdf "6.2.3 NaN propagation An operation that propagates a NaN operand to its result and has a single NaN as an input should produce a NaN with the payload of the input NaN if representable in the destination format." There might even be a slight speed-up from this too. Thanks to Duncan Murdoch for finding the reference.
This commit is contained in:
parent
5085ce2106
commit
96fc528397
@ -73,9 +73,8 @@ __FLT_ABI (sqrt) (__FLT_TYPE x)
|
|||||||
if (x_class == FP_ZERO)
|
if (x_class == FP_ZERO)
|
||||||
return __FLT_CST (-0.0);
|
return __FLT_CST (-0.0);
|
||||||
|
|
||||||
res = (signbit (x) ? -__FLT_NAN : __FLT_NAN);
|
__FLT_RPT_DOMAIN ("sqrt", x, 0.0, x);
|
||||||
__FLT_RPT_DOMAIN ("sqrt", x, 0.0, res);
|
return x;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
else if (x_class == FP_ZERO)
|
else if (x_class == FP_ZERO)
|
||||||
return __FLT_CST (0.0);
|
return __FLT_CST (0.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user