[libc-commits] [libc] [libc][math] Fix signed zeros for powf when underflow happens. (PR #112601)
via libc-commits
libc-commits at lists.llvm.org
Wed Oct 16 12:14:49 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (lntue)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/112601.diff
2 Files Affected:
- (modified) libc/src/math/generic/powf.cpp (+5-3)
- (modified) libc/test/src/math/smoke/powf_test.cpp (+2)
``````````diff
diff --git a/libc/src/math/generic/powf.cpp b/libc/src/math/generic/powf.cpp
index 8ce2465ba229cb..96a977c466f90f 100644
--- a/libc/src/math/generic/powf.cpp
+++ b/libc/src/math/generic/powf.cpp
@@ -855,9 +855,11 @@ 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);
+ float r_f = static_cast<float>(r_dd);
+
+ // Only fix signed zeros for exact zeros results.
+ return r_dd != 0 ? r_f : r_f + 0.0f;
}
} // 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..6adb9e9feb2278 100644
--- a/libc/test/src/math/smoke/powf_test.cpp
+++ b/libc/test/src/math/smoke/powf_test.cpp
@@ -190,4 +190,6 @@ TEST_F(LlvmLibcPowfTest, SpecialNumbers) {
FE_UNDERFLOW);
}
}
+
+ EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::powf(-0.015625f, 25.0f));
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/112601
More information about the libc-commits
mailing list