From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by server2.sourceware.org (Postfix, from userid 2155) id C5DB93937437; Mon, 9 Mar 2020 09:12:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 server2.sourceware.org C5DB93937437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1583745159; bh=ca/LFbvscVPZ24f0pO/rOsPaDzFAVCdd/bS4aIDw0E8=; h=From:To:Subject:Date:From; b=yw6hexh+o0HZ3gD0hqpX/iCsalxiZI4b9uhGUBiKi6Go95ztKDQ7j5j6EWJ1la5KZ 1wlyQKvNGy0dabtiS3UlH6e5fAToEn/udR/e+BygAH3xjTf1ICafvuWuzqF7BFM55D AtFfrr70u40tMT/IxH/xoU6gWZ74UtAj7F7XLinw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix error in exp in magnitude [2e-32,2e-28] X-Act-Checkin: newlib-cygwin X-Git-Author: Fabian Schriever X-Git-Refname: refs/heads/master X-Git-Oldrev: 3e7fff6b49fbdc1ab5022b145268622d8e5dedd3 X-Git-Newrev: a8a40ee5750cb8a4280379a38c1ed490262481c4 Message-Id: <20200309091239.C5DB93937437@server2.sourceware.org> Date: Mon, 9 Mar 2020 09:12:39 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Mar 2020 09:12:39 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a8a40ee5750cb8a4280379a38c1ed490262481c4 commit a8a40ee5750cb8a4280379a38c1ed490262481c4 Author: Fabian Schriever Date: Fri Mar 6 15:46:33 2020 +0100 Fix error in exp in magnitude [2e-32,2e-28] While testing the exp function we noticed some errors at the specified magnitude. Within this range the exp function returns the input value +1 as an output. We chose to run a test of 1m exponentially spaced values in the ranges [-2^-27,-2^-32] and [2^-32,2^-27] which showed 7603 and 3912 results with an error of >=0.5 ULP (compared with MPFR in 128 bit) with the highest being 0.56 ULP and 0.53 ULP. It's easy to fix by changing the magnitude at which the input value +1 is returned from <2^-28 to <2^-32 and using the polynomial instead. This reduces the number of results with an error of >=0.5 ULP to 485 and 479 in above tests, all of which are exactly 0.5 ULP. As we were already checking on exp we also took a look at expf. For expf the magnitude where the input value +1 is returned can be increased from <2^-28 to <2^-23 without accuracy loss for a slight performance improvement. To ensure this was the correct value we tested all values in the ranges [-2^-17,-2^-28] and [2^-28,2^-17] (~92.3m values each). Diff: --- newlib/libm/math/e_exp.c | 2 +- newlib/libm/math/ef_exp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/newlib/libm/math/e_exp.c b/newlib/libm/math/e_exp.c index 81ea64d..d23b116 100644 --- a/newlib/libm/math/e_exp.c +++ b/newlib/libm/math/e_exp.c @@ -142,7 +142,7 @@ P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ } x = hi - lo; } - else if(hx < 0x3e300000) { /* when |x|<2**-28 */ + else if(hx < 0x3df00000) { /* when |x|<2**-32 */ if(huge+x>one) return one+x;/* trigger inexact */ } diff --git a/newlib/libm/math/ef_exp.c b/newlib/libm/math/ef_exp.c index e817370..fb3e2ff 100644 --- a/newlib/libm/math/ef_exp.c +++ b/newlib/libm/math/ef_exp.c @@ -77,7 +77,7 @@ P5 = 4.1381369442e-08; /* 0x3331bb4c */ } x = hi - lo; } - else if(hx < 0x31800000) { /* when |x|<2**-28 */ + else if(hx < 0x34000000) { /* when |x|<2**-23 */ if(huge+x>one) return one+x;/* trigger inexact */ }