* huge powf error
@ 2020-12-11 5:51 Paul Zimmermann
2020-12-11 15:57 ` [PATCH] Fix error in powf for x close to 1 and large y Fabian Schriever
0 siblings, 1 reply; 4+ messages in thread
From: Paul Zimmermann @ 2020-12-11 5:51 UTC (permalink / raw)
To: newlib
Hi,
while pursuing my analysis of the accuracy of mathematical libraries [1],
I noticed that Newlib 3.3.0 powf(0x1.ffffeep-1,-0x1.000002p+27) gives +Inf
instead of 0xe.a9a99p+100 which is largely inside the binary32 range. (The
same issue appears with OpenLibm 0.7.0.)
Best regards,
Paul Zimmermann
[1] https://homepages.loria.fr/PZimmermann/papers/#accuracy
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Fix error in powf for x close to 1 and large y
2020-12-11 5:51 huge powf error Paul Zimmermann
@ 2020-12-11 15:57 ` Fabian Schriever
2020-12-11 17:02 ` Paul Zimmermann
2020-12-11 21:02 ` Jeff Johnston
0 siblings, 2 replies; 4+ messages in thread
From: Fabian Schriever @ 2020-12-11 15:57 UTC (permalink / raw)
To: newlib
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix error in powf for x close to 1 and large y
2020-12-11 15:57 ` [PATCH] Fix error in powf for x close to 1 and large y Fabian Schriever
@ 2020-12-11 17:02 ` Paul Zimmermann
2020-12-11 21:02 ` Jeff Johnston
1 sibling, 0 replies; 4+ messages in thread
From: Paul Zimmermann @ 2020-12-11 17:02 UTC (permalink / raw)
To: Fabian Schriever; +Cc: newlib
Dear Fabian,
that was fast! Thank you very much.
Paul
> From: Fabian Schriever <fabian.schriever@gtd-gmbh.de>
> Date: Fri, 11 Dec 2020 16:57:35 +0100
>
> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix error in powf for x close to 1 and large y
2020-12-11 15:57 ` [PATCH] Fix error in powf for x close to 1 and large y Fabian Schriever
2020-12-11 17:02 ` Paul Zimmermann
@ 2020-12-11 21:02 ` Jeff Johnston
1 sibling, 0 replies; 4+ messages in thread
From: Jeff Johnston @ 2020-12-11 21:02 UTC (permalink / raw)
To: Fabian Schriever; +Cc: Newlib
Thanks Fabian. Patch applied. Supplied sample powf call above tested
against glibc and newlib with/without patch.
-- Jeff J.
On Fri, Dec 11, 2020 at 11:02 AM Fabian Schriever <
fabian.schriever@gtd-gmbh.de> wrote:
> 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
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-12-11 21:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 5:51 huge powf error Paul Zimmermann
2020-12-11 15:57 ` [PATCH] Fix error in powf for x close to 1 and large y Fabian Schriever
2020-12-11 17:02 ` Paul Zimmermann
2020-12-11 21:02 ` Jeff Johnston
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).