[libc-commits] [libc] [libc] Fix value in Atan2f128 (PR #215023)
via libc-commits
libc-commits at lists.llvm.org
Sat Aug 8 13:48:47 PDT 2026
https://github.com/Sukumarsawant created https://github.com/llvm/llvm-project/pull/215023
It fixes the THREE_PI_OVER_4 value in atan2f128 and adds a small smoke test against the failure.
The result or comparison value is directly taken from the failure while comparing with core math :
```CPP
FAIL x=inf y=-inf ref=0x1.2d97c7f3321d234f272993d1414ap+1 z=0x1.2d97c7f3321d234f272993d1414ap-1
```
>From 071ad39c90b08638fa91b8ea9c232e1fa363497e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 9 Aug 2026 02:04:43 +0530
Subject: [PATCH 1/2] feat: fix value and add test
---
libc/src/__support/math/atan2f128.h | 2 +-
libc/test/src/math/smoke/atan2f128_test.cpp | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/math/atan2f128.h b/libc/src/__support/math/atan2f128.h
index f99de5be3472c..3c0b2620848ca 100644
--- a/libc/src/__support/math/atan2f128.h
+++ b/libc/src/__support/math/atan2f128.h
@@ -97,7 +97,7 @@ LIBC_INLINE float128 atan2f128(float128 y, float128 x) {
constexpr DFloat128 PI_OVER_4 = {Sign::POS, -128,
0xc90fdaa2'2168c234'c4c6628b'80dc1cd1_u128};
constexpr DFloat128 THREE_PI_OVER_4 = {
- Sign::POS, -128, 0x96cbe3f9'990e91a7'9394c9e8'a0a5159d_u128};
+ Sign::POS, -126, 0x96cbe3f9'990e91a7'9394c9e8'a0a5159d_u128};
// Adjustment for constant term:
// CONST_ADJ[x_sign][y_sign][recip]
diff --git a/libc/test/src/math/smoke/atan2f128_test.cpp b/libc/test/src/math/smoke/atan2f128_test.cpp
index 28b15ae71cac8..0d23c6e464e96 100644
--- a/libc/test/src/math/smoke/atan2f128_test.cpp
+++ b/libc/test/src/math/smoke/atan2f128_test.cpp
@@ -19,6 +19,8 @@ TEST_F(LlvmLibcAtan2f128Test, SpecialNumbers) {
EXPECT_FP_EQ_ALL_ROUNDING(neg_zero,
LIBC_NAMESPACE::atan2f128(neg_zero, zero));
EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::atan2f128(1.0, inf));
+ EXPECT_FP_EQ_ALL_ROUNDING(0x1.2d97c7f3321d234f272993d1414ap+1q,
+ LIBC_NAMESPACE::atan2f128(inf, neg_inf));
EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::atan2f128(-1.0, inf));
float128 x = 0x1.ffffffffffffffffffffffffffe7p1q;
>From 22aaf3833b8d4b91af3156dff8841fc5e4fd0802 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 9 Aug 2026 02:18:26 +0530
Subject: [PATCH 2/2] remove all_rounding
---
libc/test/src/math/smoke/atan2f128_test.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/math/smoke/atan2f128_test.cpp b/libc/test/src/math/smoke/atan2f128_test.cpp
index 0d23c6e464e96..0b135c5166d6a 100644
--- a/libc/test/src/math/smoke/atan2f128_test.cpp
+++ b/libc/test/src/math/smoke/atan2f128_test.cpp
@@ -19,8 +19,6 @@ TEST_F(LlvmLibcAtan2f128Test, SpecialNumbers) {
EXPECT_FP_EQ_ALL_ROUNDING(neg_zero,
LIBC_NAMESPACE::atan2f128(neg_zero, zero));
EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::atan2f128(1.0, inf));
- EXPECT_FP_EQ_ALL_ROUNDING(0x1.2d97c7f3321d234f272993d1414ap+1q,
- LIBC_NAMESPACE::atan2f128(inf, neg_inf));
EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::atan2f128(-1.0, inf));
float128 x = 0x1.ffffffffffffffffffffffffffe7p1q;
@@ -28,6 +26,9 @@ TEST_F(LlvmLibcAtan2f128Test, SpecialNumbers) {
float128 r = 0x1.921fb54442d18469898cc51701b3p-1q;
EXPECT_FP_EQ(r, LIBC_NAMESPACE::atan2f128(x, y));
+ EXPECT_FP_EQ(0x1.2d97c7f3321d234f272993d1414ap+1q,
+ LIBC_NAMESPACE::atan2f128(inf, neg_inf));
+
x = -0x1.f122e07fff556143p+3524q;
y = 0x1.f122e07fff55615b75p+6316q;
r = -0x1.ffffffffffffffe6cfcdc604fc99p-2793q;
More information about the libc-commits
mailing list