diff mbox series

math: Fix incorrect results of exp10m1f with some GCC versions

Message ID 87y11wms4v.fsf@oldenburg.str.redhat.com
State New
Headers show
Series math: Fix incorrect results of exp10m1f with some GCC versions | expand

Commit Message

Florian Weimer Nov. 6, 2024, 1:03 p.m. UTC
On GCC 11 (x86-64), the previous code produced test failures like
this one:

Failure: Test: exp10m1_towardzero (-0x1.1p+4)
Result:
 is:         -1.00000000e+00  -0x1.000000p+0
 should be:  -9.99999940e-01  -0x1.fffffep-1
 difference:  5.96046447e-08   0x1.000000p-24
 ulp       :  1.0000
 max.ulp   :  0.0000

Apply a similar fix to exp2m1f.

Tested on x86-64 with GCC 11 and GCC 14 (on systems with FMA).

Co-authored-by: Paul Zimmermann <Paul.Zimmermann@inria.fr>

---
 sysdeps/ieee754/flt-32/s_exp10m1f.c | 2 +-
 sysdeps/ieee754/flt-32/s_exp2m1f.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)


base-commit: c1560f3f75c0e892b5522c16f91b4e303f677094

Comments

Adhemerval Zanella Netto Nov. 6, 2024, 2:26 p.m. UTC | #1
On 06/11/24 10:03, Florian Weimer wrote:
> On GCC 11 (x86-64), the previous code produced test failures like
> this one:
> 
> Failure: Test: exp10m1_towardzero (-0x1.1p+4)
> Result:
>  is:         -1.00000000e+00  -0x1.000000p+0
>  should be:  -9.99999940e-01  -0x1.fffffep-1
>  difference:  5.96046447e-08   0x1.000000p-24
>  ulp       :  1.0000
>  max.ulp   :  0.0000
> 
> Apply a similar fix to exp2m1f.
> 
> Tested on x86-64 with GCC 11 and GCC 14 (on systems with FMA).
> 
> Co-authored-by: Paul Zimmermann <Paul.Zimmermann@inria.fr>

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 
> ---
>  sysdeps/ieee754/flt-32/s_exp10m1f.c | 2 +-
>  sysdeps/ieee754/flt-32/s_exp2m1f.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sysdeps/ieee754/flt-32/s_exp10m1f.c b/sysdeps/ieee754/flt-32/s_exp10m1f.c
> index 04a068ee32..ea3173a174 100644
> --- a/sysdeps/ieee754/flt-32/s_exp10m1f.c
> +++ b/sysdeps/ieee754/flt-32/s_exp10m1f.c
> @@ -40,7 +40,7 @@ __exp10m1f (float x)
>      { /* x < -7.52575 */
>        if (ax > (0xffu << 23))
>  	return x + x; /* nan */
> -      return (ux == 0xff800000) ? -0x1p+0 : -0x1p+0 + 0x1p-26f;
> +      return (ux == 0xff800000) ? -0x1p+0f : -0x1p+0f + 0x1p-26f;
>      }
>    else if (__glibc_unlikely (ax > 0x421a209au))
>      { /* x > 38.5318 */
> diff --git a/sysdeps/ieee754/flt-32/s_exp2m1f.c b/sysdeps/ieee754/flt-32/s_exp2m1f.c
> index b3f86409cc..325ffb11b0 100644
> --- a/sysdeps/ieee754/flt-32/s_exp2m1f.c
> +++ b/sysdeps/ieee754/flt-32/s_exp2m1f.c
> @@ -41,7 +41,7 @@ __exp2m1f (float x)
>      { /* x <= -25 */
>        if (ax > (0xffu << 23))
>  	return x + x; /* nan */
> -      return (ux == 0xff800000) ? -0x1p+0 : -0x1p+0 + 0x1p-26f;
> +      return (ux == 0xff800000) ? -0x1p+0f : -0x1p+0f + 0x1p-26f;
>      }
>    else if (__glibc_unlikely (ax >= 0x43000000u))
>      { /* x >= 128 */
> 
> base-commit: c1560f3f75c0e892b5522c16f91b4e303f677094
>
diff mbox series

Patch

diff --git a/sysdeps/ieee754/flt-32/s_exp10m1f.c b/sysdeps/ieee754/flt-32/s_exp10m1f.c
index 04a068ee32..ea3173a174 100644
--- a/sysdeps/ieee754/flt-32/s_exp10m1f.c
+++ b/sysdeps/ieee754/flt-32/s_exp10m1f.c
@@ -40,7 +40,7 @@  __exp10m1f (float x)
     { /* x < -7.52575 */
       if (ax > (0xffu << 23))
 	return x + x; /* nan */
-      return (ux == 0xff800000) ? -0x1p+0 : -0x1p+0 + 0x1p-26f;
+      return (ux == 0xff800000) ? -0x1p+0f : -0x1p+0f + 0x1p-26f;
     }
   else if (__glibc_unlikely (ax > 0x421a209au))
     { /* x > 38.5318 */
diff --git a/sysdeps/ieee754/flt-32/s_exp2m1f.c b/sysdeps/ieee754/flt-32/s_exp2m1f.c
index b3f86409cc..325ffb11b0 100644
--- a/sysdeps/ieee754/flt-32/s_exp2m1f.c
+++ b/sysdeps/ieee754/flt-32/s_exp2m1f.c
@@ -41,7 +41,7 @@  __exp2m1f (float x)
     { /* x <= -25 */
       if (ax > (0xffu << 23))
 	return x + x; /* nan */
-      return (ux == 0xff800000) ? -0x1p+0 : -0x1p+0 + 0x1p-26f;
+      return (ux == 0xff800000) ? -0x1p+0f : -0x1p+0f + 0x1p-26f;
     }
   else if (__glibc_unlikely (ax >= 0x43000000u))
     { /* x >= 128 */