[libc-commits] [libc] e25eacf - [libc][math] Fix the FTZ/DAZ checks for log1p. (#174424)

via libc-commits libc-commits at lists.llvm.org
Mon Jan 5 09:08:31 PST 2026


Author: lntue
Date: 2026-01-05T12:08:26-05:00
New Revision: e25eacf10c0d6718bad4e18e63757f97be9f9596

URL: https://github.com/llvm/llvm-project/commit/e25eacf10c0d6718bad4e18e63757f97be9f9596
DIFF: https://github.com/llvm/llvm-project/commit/e25eacf10c0d6718bad4e18e63757f97be9f9596.diff

LOG: [libc][math] Fix the FTZ/DAZ checks for log1p. (#174424)

The previous checks will fail with
https://github.com/llvm/llvm-project/pull/174123.
See
https://github.com/llvm/llvm-project/pull/174290#issuecomment-3708052716
for the discussion.

Added: 
    

Modified: 
    libc/src/math/generic/log1p.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/math/generic/log1p.cpp b/libc/src/math/generic/log1p.cpp
index 1595981ac309b..ddac3c2bacc05 100644
--- a/libc/src/math/generic/log1p.cpp
+++ b/libc/src/math/generic/log1p.cpp
@@ -935,7 +935,7 @@ LLVM_LIBC_FUNCTION(double, log1p, (double x)) {
       //   log(1 + x) = nextafter(x, -inf) for FE_DOWNWARD, or
       //                                       FE_TOWARDZERO and x > 0,
       //              = x                  otherwise.
-      if (x == 0.0)
+      if (x + x == 0.0)
         return x + x; // Handle FTZ/DAZ correctly.
 
       volatile float tp = 1.0f;
@@ -951,7 +951,7 @@ LLVM_LIBC_FUNCTION(double, log1p, (double x)) {
         return FPBits_t(x_u + 1).get_val();
       }
 
-      return (x + x == 0.0) ? x + x : x;
+      return x;
     }
     x_dd = fputil::exact_add(1.0, x);
   }


        


More information about the libc-commits mailing list