[llvm-branch-commits] [libc] [libc] Make atan2f128 use the emulated float128 type (PR #214980)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Aug 8 08:55:55 PDT 2026
https://github.com/Sukumarsawant created https://github.com/llvm/llvm-project/pull/214980
None
>From aaa5f191702c1af37e83f3472f53a4994770fbd3 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 8 Aug 2026 21:22:52 +0530
Subject: [PATCH 1/2] atan2f128
---
libc/shared/math/atan2f128.h | 9 +++------
libc/src/__support/math/CMakeLists.txt | 1 +
libc/src/__support/math/atan2f128.h | 19 ++++++++-----------
libc/src/math/atan2f128.h | 5 +++++
libc/src/math/generic/atan2f128.cpp | 6 +++++-
libc/src/math/hypotbf16.h | 2 +-
libc/test/shared/shared_math_test.cpp | 4 ++--
7 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/libc/shared/math/atan2f128.h b/libc/shared/math/atan2f128.h
index d7aee40c69527..19c008e33bde4 100644
--- a/libc/shared/math/atan2f128.h
+++ b/libc/shared/math/atan2f128.h
@@ -9,13 +9,12 @@
#ifndef LLVM_LIBC_SHARED_MATH_ATAN2F128_H
#define LLVM_LIBC_SHARED_MATH_ATAN2F128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_FLOAT128
-
#include "shared/libc_common.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/math/atan2f128.h"
+using LIBC_NAMESPACE::fputil::Float128;
+
namespace LIBC_NAMESPACE_DECL {
namespace shared {
@@ -24,6 +23,4 @@ using math::atan2f128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_FLOAT128
-
#endif // LLVM_LIBC_SHARED_MATH_ATAN2F128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 93d226b807a67..146ef7c4a195e 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -314,6 +314,7 @@ add_header_library(
atan2f128.h
DEPENDS
.atan_utils
+ libc.src.__support.FPUtil.float128
libc.src.__support.integer_literals
libc.src.__support.uint128
libc.src.__support.FPUtil.dyadic_float
diff --git a/libc/src/__support/math/atan2f128.h b/libc/src/__support/math/atan2f128.h
index f99de5be3472c..58e6038d33cf2 100644
--- a/libc/src/__support/math/atan2f128.h
+++ b/libc/src/__support/math/atan2f128.h
@@ -9,19 +9,18 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_FLOAT128
-
#include "atan_utils.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/FPUtil/nearest_integer.h"
#include "src/__support/integer_literals.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/uint128.h"
+using LIBC_NAMESPACE::fputil::Float128;
+
namespace LIBC_NAMESPACE_DECL {
namespace math {
@@ -81,7 +80,7 @@ namespace math {
// and relative errors bounded by:
// |(atan(u) - P(u)) / P(u)| < 2^-114.
-LIBC_INLINE float128 atan2f128(float128 y, float128 x) {
+LIBC_INLINE Float128 atan2f128(Float128 y, Float128 x) {
using DFloat128 = fputil::DyadicFloat<128>;
constexpr DFloat128 ZERO = {Sign::POS, 0, 0_u128};
@@ -106,7 +105,7 @@ LIBC_INLINE float128 atan2f128(float128 y, float128 x) {
{{MPI, PI_OVER_2}, {MPI, PI_OVER_2}}};
using namespace atan_internal;
- using FPBits = fputil::FPBits<float128>;
+ using FPBits = fputil::FPBits<Float128>;
using DFloat128 = fputil::DyadicFloat<128>;
FPBits x_bits(x), y_bits(y);
@@ -151,7 +150,7 @@ LIBC_INLINE float128 atan2f128(float128 y, float128 x) {
DFloat128 r = EXCEPTS[y_except][x_except][x_sign];
if (y_sign)
r.sign = r.sign.negate();
- return static_cast<float128>(r);
+ return static_cast<Float128>(r);
}
}
@@ -165,7 +164,7 @@ LIBC_INLINE float128 atan2f128(float128 y, float128 x) {
DFloat128 result = quick_add(const_term, quotient);
if (final_sign)
result.sign = result.sign.negate();
- return static_cast<float128>(result);
+ return static_cast<Float128>(result);
}
// Take 24 leading bits of num and den to convert to float for fast division.
@@ -203,13 +202,11 @@ LIBC_INLINE float128 atan2f128(float128 y, float128 x) {
if (final_sign)
r.sign = r.sign.negate();
- return static_cast<float128>(r);
+ return static_cast<Float128>(r);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_FLOAT128
-
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F128_H
diff --git a/libc/src/math/atan2f128.h b/libc/src/math/atan2f128.h
index 26f7ec624940c..57baca529405e 100644
--- a/libc/src/math/atan2f128.h
+++ b/libc/src/math/atan2f128.h
@@ -9,9 +9,14 @@
#ifndef LLVM_LIBC_SRC_MATH_ATAN2F128_H
#define LLVM_LIBC_SRC_MATH_ATAN2F128_H
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#ifndef LIBC_TYPES_HAS_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_FLOAT128
+
namespace LIBC_NAMESPACE_DECL {
float128 atan2f128(float128 x, float128 y);
diff --git a/libc/src/math/generic/atan2f128.cpp b/libc/src/math/generic/atan2f128.cpp
index ec051ddd4e00b..c3b7d6c0fe178 100644
--- a/libc/src/math/generic/atan2f128.cpp
+++ b/libc/src/math/generic/atan2f128.cpp
@@ -9,10 +9,14 @@
#include "src/math/atan2f128.h"
#include "src/__support/math/atan2f128.h"
+#ifndef LIBC_TYPES_HAS_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_FLOAT128
+
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, atan2f128, (float128 y, float128 x)) {
- return math::atan2f128(y, x);
+ return fputil::cast<float128>(math::atan2f128(Float128(y), Float128(x)));
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/hypotbf16.h b/libc/src/math/hypotbf16.h
index db1365d791dba..d8623ceb3283e 100644
--- a/libc/src/math/hypotbf16.h
+++ b/libc/src/math/hypotbf16.h
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE_DECL {
-bfloat16 hypotbf16(bfloat16 x, bfloat16 y);
+bfloat16 hypotbf16(bfloat16 x, bfloata16 y);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 3d52f190f55c1..f0879f83f2b85 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -584,6 +584,8 @@ using LIBC_NAMESPACE::fputil::Float128;
TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+ EXPECT_FP_EQ(float128(0.0),
+ LIBC_NAMESPACE::shared::atan2f128(float128(0.0), float128(0.0)));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
@@ -592,8 +594,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<float128>;
int exponent;
- EXPECT_FP_EQ(float128(0.0),
- LIBC_NAMESPACE::shared::atan2f128(float128(0.0), float128(0.0)));
EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::ffmaf128(
float128(0.0), float128(0.0), float128(0.0)));
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::shared::fsqrtf128(float128(1.0f)));
>From f0b97df711b7ea83c9fb1901df85a8392eaecc09 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 8 Aug 2026 21:24:59 +0530
Subject: [PATCH 2/2] nit
---
libc/src/math/hypotbf16.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/math/hypotbf16.h b/libc/src/math/hypotbf16.h
index d8623ceb3283e..db1365d791dba 100644
--- a/libc/src/math/hypotbf16.h
+++ b/libc/src/math/hypotbf16.h
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE_DECL {
-bfloat16 hypotbf16(bfloat16 x, bfloata16 y);
+bfloat16 hypotbf16(bfloat16 x, bfloat16 y);
} // namespace LIBC_NAMESPACE_DECL
More information about the llvm-branch-commits
mailing list