From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gtd-gmbh.de (mail.gtd.eu [46.24.46.35]) by sourceware.org (Postfix) with ESMTPS id B6C993850430 for ; Fri, 11 Dec 2020 16:02:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B6C993850430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gtd-gmbh.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=prvs=161443e5a6=fabian.schriever@gtd-gmbh.de X-MDAV-Result: clean X-MDAV-Processed: gtd-gmbh.de, Fri, 11 Dec 2020 16:57:40 +0100 Received: from localhost.localdomain [(109.90.104.197)] by gtd-gmbh.de (MDaemon PRO v19.5.5) with ESMTPA id md50014545858.msg; Fri, 11 Dec 2020 16:57:38 +0100 X-Spam-Processed: gtd-gmbh.de, Fri, 11 Dec 2020 16:57:38 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 109.90.104.197 X-MDHelo: localhost.localdomain X-MDArrival-Date: Fri, 11 Dec 2020 16:57:38 +0100 X-Authenticated-Sender: fabian.schriever@gtd-gmbh.de X-Return-Path: prvs=161443e5a6=fabian.schriever@gtd-gmbh.de X-Envelope-From: fabian.schriever@gtd-gmbh.de X-MDaemon-Deliver-To: newlib@sourceware.org From: Fabian Schriever To: newlib@sourceware.org Subject: [PATCH] Fix error in powf for x close to 1 and large y Date: Fri, 11 Dec 2020 16:57:35 +0100 Message-Id: <20201211155735.2645-1-fabian.schriever@gtd-gmbh.de> X-Mailer: git-send-email 2.26.1.windows.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2020 16:02:14 -0000 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]. --- 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 */ -- 2.26.1.windows.1