[libc-commits] [libc] [libc][math] Update error bound for log1p to compensate for directional rounding. (PR #87893)
via libc-commits
libc-commits at lists.llvm.org
Sat Apr 6 14:11:57 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/87893.diff
2 Files Affected:
- (modified) libc/src/math/generic/log1p.cpp (+3-2)
- (modified) libc/test/src/math/log1p_test.cpp (+2-1)
``````````diff
diff --git a/libc/src/math/generic/log1p.cpp b/libc/src/math/generic/log1p.cpp
index 83bd753cde5da8..2b187080a057b4 100644
--- a/libc/src/math/generic/log1p.cpp
+++ b/libc/src/math/generic/log1p.cpp
@@ -28,8 +28,9 @@ using LIBC_NAMESPACE::operator""_u128;
namespace {
-// Extra errors from P is from using x^2 to reduce evaluation latency.
-constexpr double P_ERR = 0x1.0p-50;
+// Extra errors from P is from using x^2 to reduce evaluation latency and
+// directional rounding.
+constexpr double P_ERR = 0x1.0p-49;
// log(2) with 128-bit precision generated by SageMath with:
// def format_hex(value):
diff --git a/libc/test/src/math/log1p_test.cpp b/libc/test/src/math/log1p_test.cpp
index 5e461c91518b1f..47dfa406ec257c 100644
--- a/libc/test/src/math/log1p_test.cpp
+++ b/libc/test/src/math/log1p_test.cpp
@@ -34,7 +34,7 @@ TEST_F(LlvmLibcLog1pTest, SpecialNumbers) {
}
TEST_F(LlvmLibcLog1pTest, TrickyInputs) {
- constexpr int N = 41;
+ constexpr int N = 42;
constexpr uint64_t INPUTS[N] = {
0x3ff0000000000000, // x = 1.0
0x4024000000000000, // x = 10.0
@@ -65,6 +65,7 @@ TEST_F(LlvmLibcLog1pTest, TrickyInputs) {
0x3c90c40cef04efb5, 0x449d2ccad399848e, 0x4aa12ccdffd9d2ec,
0x5656f070b92d36ce, 0x6db06dcb74f76bcc, 0x7f1954e72ffd4596,
0x5671e2f1628093e4, 0x73dac56e2bf1a951, 0x8001bc6879ea14c5,
+ 0x45ca5f497ec291df, // x = 0x1.a5f497ec291dfp+93
};
for (int i = 0; i < N; ++i) {
double x = FPBits(INPUTS[i]).get_val();
``````````
</details>
https://github.com/llvm/llvm-project/pull/87893
More information about the libc-commits
mailing list