[libc-commits] [libc] [libc][math] Fix the FTZ/DAZ checks for log1p. (PR #174424)
via libc-commits
libc-commits at lists.llvm.org
Mon Jan 5 07:44:17 PST 2026
https://github.com/lntue created https://github.com/llvm/llvm-project/pull/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.
>From 4d1c25c038622e41761c3d45c9acfd731afcbaa1 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 5 Jan 2026 15:40:35 +0000
Subject: [PATCH] [libc][math] Fix the FTZ/DAZ checks for log1p.
---
libc/src/math/generic/log1p.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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