4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-02 04:20:28 +08:00

Fix error in powf for x close to 1 and large y

This patch fixes the error found by Paul Zimmermann (see
https://homepages.loria.fr/PZimmermann/papers/#accuracy) regarding x
close to 1 and rather large y (specifically he found the case
powf(0x1.ffffeep-1,-0x1.000002p+27) which returns +Inf instead of the
correct value). We found 2 more values for x which show the same faulty
behaviour, and all 3 are fixed with this patch. We have tested all
combinations for x in [+1.fffdfp-1, +1.00020p+0] and y in
[-1.000007p+27, -1.000002p+27] and [1.000002p+27,1.000007p+27].
This commit is contained in:
Fabian Schriever 2020-12-11 16:57:35 +01:00 committed by Ken Brown
parent 90400463f3
commit 39f2545591

View File

@ -138,7 +138,7 @@ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/
/* |y| is huge */ /* |y| is huge */
if(iy>0x4d000000) { /* if |y| > 2**27 */ if(iy>0x4d000000) { /* if |y| > 2**27 */
/* over/underflow if x is not close to one */ /* over/underflow if x is not close to one */
if(ix<0x3f7ffff8) return (hy<0)? __math_oflowf(0):__math_uflowf(0); if(ix<0x3f7ffff4) return (hy<0)? __math_oflowf(0):__math_uflowf(0);
if(ix>0x3f800007) return (hy>0)? __math_oflowf(0):__math_uflowf(0); if(ix>0x3f800007) return (hy>0)? __math_oflowf(0):__math_uflowf(0);
/* now |1-x| is tiny <= 2**-20, suffice to compute /* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */ log(x) by x-x^2/2+x^3/3-x^4/4 */