From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2134) id 960683857C4F; Fri, 11 Dec 2020 21:00:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 960683857C4F Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix error in powf for x close to 1 and large y X-Act-Checkin: newlib-cygwin X-Git-Author: Fabian Schriever X-Git-Refname: refs/heads/master X-Git-Oldrev: 14123c991b3b833e93a9dbb66c23beaf58c9ebab X-Git-Newrev: cf1ef2dc5b95342fa337141b3b1ec85aac73229f Message-Id: <20201211210024.960683857C4F@sourceware.org> Date: Fri, 11 Dec 2020 21:00:24 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2020 21:00:24 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=cf1ef2dc5b95342fa337141b3b1ec85aac73229f commit cf1ef2dc5b95342fa337141b3b1ec85aac73229f Author: Fabian Schriever Date: Fri Dec 11 16:57:35 2020 +0100 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]. Diff: --- newlib/libm/math/ef_pow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newlib/libm/math/ef_pow.c b/newlib/libm/math/ef_pow.c index e3579f071..07b225f8c 100644 --- a/newlib/libm/math/ef_pow.c +++ b/newlib/libm/math/ef_pow.c @@ -138,7 +138,7 @@ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ /* |y| is huge */ if(iy>0x4d000000) { /* if |y| > 2**27 */ /* 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); /* now |1-x| is tiny <= 2**-20, suffice to compute log(x) by x-x^2/2+x^3/3-x^4/4 */