[libc-commits] [libc] 170dab9 - [libc][math] Fix signed zeros for powf when underflow happens. (#112601)
via libc-commits
libc-commits at lists.llvm.org
Fri Oct 18 11:26:09 PDT 2024
Author: lntue
Date: 2024-10-18T14:26:05-04:00
New Revision: 170dab9972df3f6e905502db1846bb05fb444ec4
URL: https://github.com/llvm/llvm-project/commit/170dab9972df3f6e905502db1846bb05fb444ec4
DIFF: https://github.com/llvm/llvm-project/commit/170dab9972df3f6e905502db1846bb05fb444ec4.diff
LOG: [libc][math] Fix signed zeros for powf when underflow happens. (#112601)
Added:
Modified:
libc/src/math/generic/powf.cpp
libc/test/src/math/smoke/powf_test.cpp
Removed:
################################################################################
diff --git a/libc/src/math/generic/powf.cpp b/libc/src/math/generic/powf.cpp
index 8ce2465ba229cb..83477c6ef2aceb 100644
--- a/libc/src/math/generic/powf.cpp
+++ b/libc/src/math/generic/powf.cpp
@@ -855,9 +855,9 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
: 0.0;
exp2_hi_mid_dd.hi = exp2_hi_mid;
- return static_cast<float>(
- powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd)) +
- 0.0f;
+ double r_dd = powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd);
+
+ return static_cast<float>(r_dd);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/powf_test.cpp b/libc/test/src/math/smoke/powf_test.cpp
index bd4f98e30fbdc7..a0f66f2733a1ea 100644
--- a/libc/test/src/math/smoke/powf_test.cpp
+++ b/libc/test/src/math/smoke/powf_test.cpp
@@ -190,4 +190,7 @@ TEST_F(LlvmLibcPowfTest, SpecialNumbers) {
FE_UNDERFLOW);
}
}
+
+ EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::powf(-0.015625f, 25.0f));
+ EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::powf(-0.015625f, 26.0f));
}
More information about the libc-commits
mailing list