]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix potential underflow on ldbl-128 erfl
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 30 Jan 2024 13:45:14 +0000 (13:45 +0000)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Oct 2025 16:54:55 +0000 (13:54 -0300)
The multiplication is only required if the branch is taken, and the
compiler might not optimize it away.

If fixes the following issues when testcase is built with clang:

FAIL: math/test-ldouble-erf
Failure: erf (-0x4p-16384): Exception "Underflow" set
Failure: erf (0x1p-10000): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf (0x4p-16384): Exception "Underflow" set
Failure: erf_downward (-0x4p-16384): Exception "Underflow" set
Failure: erf_downward (0x1p-10000): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf_downward (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf_downward (0x4p-16384): Exception "Underflow" set
Failure: erf_towardzero (-0x4p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x1p-10000): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf_towardzero (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf_towardzero (0x4p-16384): Exception "Underflow" set
Failure: erf_upward (-0x4p-16384): Exception "Underflow" set
Failure: erf_upward (0x1p-10000): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f38760a41abb84p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f38760a41abb88p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f4p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded54f8p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded5518p-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded551cp-16384): Exception "Underflow" set
Failure: erf_upward (0x3.8b7f12369ded552p-16384): Exception "Underflow" set
Failure: erf_upward (0x4p-16384): Exception "Underflow" set

Checked on aarch64-linux-gnu with gcc and clang.

sysdeps/ieee754/ldbl-128/s_erfl.c

index 1cbedc249d54ab01569259daa6ba865938f8b630..e52d88bde3dadbffc3535a35f290a5a6eef432c3 100644 (file)
@@ -778,7 +778,6 @@ __erfl (_Float128 x)
     }
   u.parts32.w0 = ix;
   a = u.value;
-  z = x * x;
   if (ix < 0x3ffec000)  /* a < 0.875 */
     {
       if (ix < 0x3fc60000) /* |x|<2**-57 */
@@ -792,6 +791,7 @@ __erfl (_Float128 x)
            }
          return x + efx * x;
        }
+      z = x * x;
       y = a + a * neval (z, TN1, NTN1) / deval (z, TD1, NTD1);
     }
   else