[libc-commits] [libc] [libc] Make ceilf128 use the emulated float128 type (PR #207735)
via libc-commits
libc-commits at lists.llvm.org
Mon Jul 6 06:29:19 PDT 2026
https://github.com/Sukumarsawant created https://github.com/llvm/llvm-project/pull/207735
None
>From d496eabee5db2122fa827560991296264bc5da37 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 30 May 2026 02:08:42 +0530
Subject: [PATCH 01/51] test: float128 skeleton
---
libc/src/__support/FPUtil/CMakeLists.txt | 11 ++++++
libc/src/__support/FPUtil/float128.h | 45 ++++++++++++++++++++++++
2 files changed, 56 insertions(+)
create mode 100644 libc/src/__support/FPUtil/float128.h
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index d45dd82560788..a88986b4992f8 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -294,4 +294,15 @@ add_header_library(
libc.src.__support.macros.properties.types
)
+add_header_library(
+ float128
+ HDRS
+ float128.h
+ DEPENDS
+ .fp_bits
+ libc.hdr.fenv_macros
+ libc.src.__support.CPP.bit
+ libc.src.__support.uint128
+)
+
add_subdirectory(generic)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
new file mode 100644
index 0000000000000..73f450f1d41a8
--- /dev/null
+++ b/libc/src/__support/FPUtil/float128.h
@@ -0,0 +1,45 @@
+//===-- Utilities for Float128 data type -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
+#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
+
+#include "FPBits.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/CPP/bit.h"
+#include "src/__support/uint128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+
+struct Float128 {
+ UInt128 bits;
+ // Testing
+ constexpr Float128() = default;
+ /* TODO: precision
+ TODO: explicit so it does not convert without warn ( Done )
+ VERIFY : template <cpp::enable_if_t<fputil::get_fp_type<Double>() ==
+ fputil::FPType::IEEE754_Binary64,
+ int> = 0>
+ */
+ constexpr explicit Float128(double x) {
+ FPBits<double> x_bits(x);
+ uint64_t val = x_bits.uintval();
+ bits = static_cast<UInt128>(val) << 64;
+ }
+
+ constexpr explicit operator double() const {
+ uint64_t val = static_cast<uint64_t>(bits >> 64U);
+ return cpp::bit_cast<double>(val);
+ }
+};
+
+} // namespace fputil
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
>From a3d9289ebd715ed0e8117983ebf9c3129e6b6925 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 2 Jun 2026 14:00:26 +0530
Subject: [PATCH 02/51] Add small smoke test
---
.../CPP/type_traits/is_floating_point.h | 2 +-
libc/src/__support/FPUtil/CMakeLists.txt | 4 +-
libc/src/__support/FPUtil/FPBits.h | 13 +++++-
libc/src/__support/FPUtil/float128.h | 41 +++++++++++--------
libc/src/__support/macros/properties/types.h | 8 ++++
libc/test/src/math/smoke/CMakeLists.txt | 10 +++++
libc/test/src/math/smoke/float128_test.cpp | 25 +++++++++++
7 files changed, 81 insertions(+), 22 deletions(-)
create mode 100644 libc/test/src/math/smoke/float128_test.cpp
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index 9dc77ad7ee0ea..ab4191868517e 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -37,7 +37,7 @@ template <typename T> struct is_floating_point {
float128
#endif
,
- bfloat16>();
+ bfloat16, fputil::Float128>();
};
template <typename T>
LIBC_INLINE_VAR constexpr bool is_floating_point_v =
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index a88986b4992f8..20e1c01bb8ca1 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -299,9 +299,9 @@ add_header_library(
HDRS
float128.h
DEPENDS
- .fp_bits
- libc.hdr.fenv_macros
libc.src.__support.CPP.bit
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
libc.src.__support.uint128
)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index c52699e17e225..5b7461a44cff5 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -37,7 +37,8 @@ enum class FPType {
IEEE754_Binary64,
IEEE754_Binary128,
X86_Binary80,
- BFloat16
+ BFloat16,
+ Float128
};
// The classes hierarchy is as follows:
@@ -146,6 +147,14 @@ template <> struct FPLayout<FPType::BFloat16> {
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
};
+template <> struct FPLayout<FPType::Float128> {
+ using StorageType = UInt128;
+ LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
+ LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
+ LIBC_INLINE_VAR static constexpr int SIG_LEN = 112;
+ LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
+};
+
// FPStorage derives useful constants from the FPLayout above.
template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
using UP = FPLayout<fp_type>;
@@ -813,6 +822,8 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
#endif
else if constexpr (cpp::is_same_v<UnqualT, bfloat16>)
return FPType::BFloat16;
+ else if constexpr (cpp::is_same_v<UnqualT, Float128>)
+ return FPType::Float128;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
}
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 73f450f1d41a8..ca5c49ddf11d7 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -1,4 +1,8 @@
+<<<<<<< HEAD
//===-- Utilities for Float128 data type -----------------------*- C++ -*-===//
+=======
+//===-- Definition for Float128 data type -----------------------*- C++ -*-===//
+>>>>>>> f128-test
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,33 +13,34 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
-#include "FPBits.h"
-#include "hdr/fenv_macros.h"
-#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/bit.h" // cpp::bit_cast
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
+#include <stdint.h>
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
struct Float128 {
UInt128 bits;
- // Testing
- constexpr Float128() = default;
- /* TODO: precision
- TODO: explicit so it does not convert without warn ( Done )
- VERIFY : template <cpp::enable_if_t<fputil::get_fp_type<Double>() ==
- fputil::FPType::IEEE754_Binary64,
- int> = 0>
- */
- constexpr explicit Float128(double x) {
- FPBits<double> x_bits(x);
- uint64_t val = x_bits.uintval();
- bits = static_cast<UInt128>(val) << 64;
+
+ LIBC_INLINE Float128() = default;
+
+ LIBC_INLINE constexpr explicit Float128(double x) : bits(0) {
+ uint64_t d = cpp::bit_cast<uint64_t>(x);
+ bits = static_cast<UInt128>(d) << 64U;
}
- constexpr explicit operator double() const {
- uint64_t val = static_cast<uint64_t>(bits >> 64U);
- return cpp::bit_cast<double>(val);
+ LIBC_INLINE constexpr explicit operator double() const {
+ return cpp::bit_cast<double>(static_cast<uint64_t>(bits >> 64U));
+ }
+
+ LIBC_INLINE constexpr bool operator==(Float128 other) const {
+ return bits == other.bits;
+ }
+ LIBC_INLINE constexpr bool operator!=(Float128 other) const {
+ return bits != other.bits;
}
};
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 3259c8a6a1d12..d94f6068984df 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -58,6 +58,14 @@ using float16 = _Float16;
// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by
// "include/llvm-libc-types/float128.h"
+// -- Emulated float128 support ------------------------------------------------
+// Float128 is always available regardless of native __float128 support.
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+struct Float128;
+}
+} // namespace LIBC_NAMESPACE_DECL
+
// -- bfloat16 support ---------------------------------------------------------
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index e4e2fb11438d4..3081a62552c49 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1,6 +1,16 @@
add_custom_target(libc-math-smoke-tests)
add_dependencies(libc-math-unittests libc-math-smoke-tests)
+add_libc_unittest(
+ float128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ float128_test.cpp
+ DEPENDS
+ libc.src.__support.FPUtil.float128
+)
+
add_fp_unittest(
cosf_test
SUITE
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
new file mode 100644
index 0000000000000..738e5ec703f00
--- /dev/null
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -0,0 +1,25 @@
+//===-- Unittests for Float128 emulated type -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/float128.h"
+#include "src/__support/uint128.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
+
+TEST(LlvmLibcFloat128Test, DefaultConstructor) {
+ Float128 x;
+ (void)x;
+}
+
+TEST(LlvmLibcFloat128Test, Equality) {
+ Float128 a(1.0), b(1.0), c(2.0);
+ ASSERT_TRUE(a == b);
+ ASSERT_TRUE(a != c);
+ ASSERT_TRUE(b != c);
+}
>From 661bb024ae0ee81eedb36a2f7c355b726fd1e8c5 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 2 Jun 2026 14:06:05 +0530
Subject: [PATCH 03/51] nit
---
libc/src/__support/FPUtil/float128.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index ca5c49ddf11d7..c7835d7376853 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -1,8 +1,4 @@
-<<<<<<< HEAD
-//===-- Utilities for Float128 data type -----------------------*- C++ -*-===//
-=======
//===-- Definition for Float128 data type -----------------------*- C++ -*-===//
->>>>>>> f128-test
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From cc98e96938c6b118f691928d1d4a183225c11727 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 2 Jun 2026 15:13:25 +0530
Subject: [PATCH 04/51] nit
---
libc/src/__support/FPUtil/float128.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index c7835d7376853..cc72692e8a22f 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
-#include "src/__support/CPP/bit.h" // cpp::bit_cast
+#include "src/__support/CPP/bit.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
@@ -24,8 +24,8 @@ struct Float128 {
LIBC_INLINE Float128() = default;
LIBC_INLINE constexpr explicit Float128(double x) : bits(0) {
- uint64_t d = cpp::bit_cast<uint64_t>(x);
- bits = static_cast<UInt128>(d) << 64U;
+ uint64_t x_bits = cpp::bit_cast<uint64_t>(x);
+ bits = static_cast<UInt128>(x_bits) << 64U;
}
LIBC_INLINE constexpr explicit operator double() const {
>From e2c57558a0231dbd6d5b16ba16a184c8c7650674 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 2 Jun 2026 20:52:36 +0530
Subject: [PATCH 05/51] temp commit for rebase
---
libc/src/__support/CPP/type_traits/is_floating_point.h | 5 ++++-
libc/src/__support/FPUtil/cast.h | 4 +++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index ab4191868517e..d53dcd4961ab6 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -37,7 +37,10 @@ template <typename T> struct is_floating_point {
float128
#endif
,
- bfloat16, fputil::Float128>();
+ bfloat16
+
+ ,
+ fputil::Float128>();
};
template <typename T>
LIBC_INLINE_VAR constexpr bool is_floating_point_v =
diff --git a/libc/src/__support/FPUtil/cast.h b/libc/src/__support/FPUtil/cast.h
index 54c80e862523a..4fc5ea0893ebe 100644
--- a/libc/src/__support/FPUtil/cast.h
+++ b/libc/src/__support/FPUtil/cast.h
@@ -31,7 +31,9 @@ cast(InType x) {
return x;
} else {
if constexpr (cpp::is_same_v<OutType, bfloat16> ||
- cpp::is_same_v<InType, bfloat16>
+ cpp::is_same_v<InType, bfloat16> ||
+ cpp::is_same_v<OutType, Float128> ||
+ cpp::is_same_v<InType, Float128>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<OutType, float16> ||
cpp::is_same_v<InType, float16>
>From 7d553ae939c1183cdb2fedc4cf2fa2a6b77c0e41 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 2 Jun 2026 22:24:48 +0530
Subject: [PATCH 06/51] feat: comparison operator overload
---
libc/src/__support/FPUtil/CMakeLists.txt | 2 ++
libc/src/__support/FPUtil/cast.h | 4 ++--
libc/src/__support/FPUtil/dyadic_float.h | 2 +-
libc/src/__support/FPUtil/float128.h | 23 ++++++++++++++++++--
libc/src/__support/macros/properties/types.h | 3 +++
libc/test/src/math/smoke/float128_test.cpp | 8 ++++++-
6 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 20e1c01bb8ca1..c49d873b026e2 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -303,6 +303,8 @@ add_header_library(
libc.src.__support.macros.attributes
libc.src.__support.macros.config
libc.src.__support.uint128
+ libc.src.__support.CPP.type_traits
+ .comparison_operations
)
add_subdirectory(generic)
diff --git a/libc/src/__support/FPUtil/cast.h b/libc/src/__support/FPUtil/cast.h
index 4fc5ea0893ebe..e7b2caf92fe4a 100644
--- a/libc/src/__support/FPUtil/cast.h
+++ b/libc/src/__support/FPUtil/cast.h
@@ -32,8 +32,8 @@ cast(InType x) {
} else {
if constexpr (cpp::is_same_v<OutType, bfloat16> ||
cpp::is_same_v<InType, bfloat16> ||
- cpp::is_same_v<OutType, Float128> ||
- cpp::is_same_v<InType, Float128>
+ cpp::is_same_v<OutType, float128> ||
+ cpp::is_same_v<InType, float128>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<OutType, float16> ||
cpp::is_same_v<InType, float16>
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index f1ac39e97c52b..95e990554210c 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -438,7 +438,7 @@ template <size_t Bits> struct DyadicFloat {
(FPBits<T>::FRACTION_LEN < Bits),
void>>
LIBC_INLINE LIBC_CONSTEXPR_DEFAULT T as() const {
- if constexpr (cpp::is_same_v<T, bfloat16>
+ if constexpr (cpp::is_same_v<T, bfloat16> || cpp::is_same_v<T, float128>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<T, float16>
#endif
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index cc72692e8a22f..d887153f58afb 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -10,6 +10,8 @@
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/FPUtil/comparison_operations.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
@@ -33,10 +35,27 @@ struct Float128 {
}
LIBC_INLINE constexpr bool operator==(Float128 other) const {
- return bits == other.bits;
+ return fputil::equals(*this, other);
}
+
LIBC_INLINE constexpr bool operator!=(Float128 other) const {
- return bits != other.bits;
+ return !fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<(Float128 other) const {
+ return fputil::less_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<=(Float128 other) const {
+ return fputil::less_than_or_equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>(Float128 other) const {
+ return fputil::greater_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>=(Float128 other) const {
+ return fputil::greater_than_or_equals(*this, other);
}
};
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index d94f6068984df..02d08867a4c9f 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -66,6 +66,9 @@ struct Float128;
}
} // namespace LIBC_NAMESPACE_DECL
+#ifndef LIBC_TYPES_HAS_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_FLOAT128
// -- bfloat16 support ---------------------------------------------------------
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index 738e5ec703f00..29fcc73384fd5 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -17,9 +17,15 @@ TEST(LlvmLibcFloat128Test, DefaultConstructor) {
(void)x;
}
-TEST(LlvmLibcFloat128Test, Equality) {
+TEST(LlvmLibcFloat128Test, operators) {
Float128 a(1.0), b(1.0), c(2.0);
+
+ // comparison operators
ASSERT_TRUE(a == b);
ASSERT_TRUE(a != c);
ASSERT_TRUE(b != c);
+ ASSERT_TRUE(c > b);
+ ASSERT_TRUE(a >= b);
+ ASSERT_TRUE(b <= c);
+ ASSERT_TRUE(a < c);
}
>From 93adc3a69b831a86f60dc093bb53ed9258233b3c Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 3 Jun 2026 00:02:22 +0530
Subject: [PATCH 07/51] marking default const , constexpr
---
libc/src/__support/FPUtil/float128.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index d887153f58afb..c9db7fd683bd1 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -23,7 +23,7 @@ namespace fputil {
struct Float128 {
UInt128 bits;
- LIBC_INLINE Float128() = default;
+ LIBC_INLINE constexpr Float128() = default;
LIBC_INLINE constexpr explicit Float128(double x) : bits(0) {
uint64_t x_bits = cpp::bit_cast<uint64_t>(x);
>From ad3d447acf007ac5fe58f6c93e0c14a913091413 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 3 Jun 2026 01:02:42 +0530
Subject: [PATCH 08/51] testing alias + removed constexpr for def const
---
libc/src/__support/FPUtil/cast.h | 4 ++--
libc/src/__support/FPUtil/dyadic_float.h | 2 +-
libc/src/__support/FPUtil/float128.h | 2 +-
libc/src/__support/macros/properties/types.h | 6 +++---
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/FPUtil/cast.h b/libc/src/__support/FPUtil/cast.h
index e7b2caf92fe4a..4fc5ea0893ebe 100644
--- a/libc/src/__support/FPUtil/cast.h
+++ b/libc/src/__support/FPUtil/cast.h
@@ -32,8 +32,8 @@ cast(InType x) {
} else {
if constexpr (cpp::is_same_v<OutType, bfloat16> ||
cpp::is_same_v<InType, bfloat16> ||
- cpp::is_same_v<OutType, float128> ||
- cpp::is_same_v<InType, float128>
+ cpp::is_same_v<OutType, Float128> ||
+ cpp::is_same_v<InType, Float128>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<OutType, float16> ||
cpp::is_same_v<InType, float16>
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 95e990554210c..c218632131934 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -438,7 +438,7 @@ template <size_t Bits> struct DyadicFloat {
(FPBits<T>::FRACTION_LEN < Bits),
void>>
LIBC_INLINE LIBC_CONSTEXPR_DEFAULT T as() const {
- if constexpr (cpp::is_same_v<T, bfloat16> || cpp::is_same_v<T, float128>
+ if constexpr (cpp::is_same_v<T, bfloat16> || cpp::is_same_v<T, Float128>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<T, float16>
#endif
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index c9db7fd683bd1..d887153f58afb 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -23,7 +23,7 @@ namespace fputil {
struct Float128 {
UInt128 bits;
- LIBC_INLINE constexpr Float128() = default;
+ LIBC_INLINE Float128() = default;
LIBC_INLINE constexpr explicit Float128(double x) : bits(0) {
uint64_t x_bits = cpp::bit_cast<uint64_t>(x);
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 02d08867a4c9f..7b861640c785d 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -66,9 +66,9 @@ struct Float128;
}
} // namespace LIBC_NAMESPACE_DECL
-#ifndef LIBC_TYPES_HAS_FLOAT128
-using float128 = LIBC_NAMESPACE::fputil::Float128;
-#endif // LIBC_TYPES_HAS_FLOAT128
+// #ifndef LIBC_TYPES_HAS_FLOAT128
+// using float128 = LIBC_NAMESPACE::fputil::Float128;
+// #endif // LIBC_TYPES_HAS_FLOAT128
// -- bfloat16 support ---------------------------------------------------------
namespace LIBC_NAMESPACE_DECL {
>From 23d5aa0f762cd0ccb8913a2e8ced4a3ec12773ec Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 3 Jun 2026 13:40:43 +0530
Subject: [PATCH 09/51] template + LIBC_CONSTEXPR_DEFAULT
---
libc/src/__support/FPUtil/float128.h | 30 ++++++++++++++++------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index d887153f58afb..97c0daf79c546 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
-#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
+#include "src/__support/FPUtil/cast.h"
#include "src/__support/FPUtil/comparison_operations.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
@@ -25,36 +25,40 @@ struct Float128 {
LIBC_INLINE Float128() = default;
- LIBC_INLINE constexpr explicit Float128(double x) : bits(0) {
- uint64_t x_bits = cpp::bit_cast<uint64_t>(x);
- bits = static_cast<UInt128>(x_bits) << 64U;
+ template <typename T> LIBC_INLINE constexpr explicit Float128(T x) : bits(0) {
+ if constexpr (cpp::is_floating_point_v<T>) {
+ bits = fputil::cast<Float128>(x).bits;
+ }
+ // TODO: add rem after testing
}
- LIBC_INLINE constexpr explicit operator double() const {
- return cpp::bit_cast<double>(static_cast<uint64_t>(bits >> 64U));
+ template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T> &&
+ !cpp::is_same_v<T, Float128>,
+ int> = 0>
+ LIBC_INLINE LIBC_CONSTEXPR_DEFAULT operator T() const {
+ return fputil::cast<T>(*this);
}
-
- LIBC_INLINE constexpr bool operator==(Float128 other) const {
+ LIBC_INLINE constexpr bool operator==(Float128 &other) const {
return fputil::equals(*this, other);
}
- LIBC_INLINE constexpr bool operator!=(Float128 other) const {
+ LIBC_INLINE constexpr bool operator!=(Float128 &other) const {
return !fputil::equals(*this, other);
}
- LIBC_INLINE constexpr bool operator<(Float128 other) const {
+ LIBC_INLINE constexpr bool operator<(Float128 &other) const {
return fputil::less_than(*this, other);
}
- LIBC_INLINE constexpr bool operator<=(Float128 other) const {
+ LIBC_INLINE constexpr bool operator<=(Float128 &other) const {
return fputil::less_than_or_equals(*this, other);
}
- LIBC_INLINE constexpr bool operator>(Float128 other) const {
+ LIBC_INLINE constexpr bool operator>(Float128 &other) const {
return fputil::greater_than(*this, other);
}
- LIBC_INLINE constexpr bool operator>=(Float128 other) const {
+ LIBC_INLINE constexpr bool operator>=(Float128 &other) const {
return fputil::greater_than_or_equals(*this, other);
}
};
>From 29b71415f02153757c9807087c2ac553d074faf2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 4 Jun 2026 20:34:00 +0530
Subject: [PATCH 10/51] testing double?
---
libc/test/src/math/smoke/float128_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index 29fcc73384fd5..f2f6d31007754 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -18,7 +18,7 @@ TEST(LlvmLibcFloat128Test, DefaultConstructor) {
}
TEST(LlvmLibcFloat128Test, operators) {
- Float128 a(1.0), b(1.0), c(2.0);
+ Float128 a(1.0f), b(1.0f), c(2.0f);
// comparison operators
ASSERT_TRUE(a == b);
>From 98b2e78af06dd3033361b1382b5aa367ae5f98c9 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 4 Jun 2026 21:49:40 +0530
Subject: [PATCH 11/51] test static assert
---
libc/src/__support/FPUtil/bfloat16.h | 7 +++++++
libc/src/__support/FPUtil/float128.h | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index ce4e3160a0963..cf3fefe75bff3 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -135,4 +135,11 @@ struct BFloat16 {
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
+static_assert(
+ LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::BFloat16>::value);
+static_assert(
+ LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::BFloat16>::value);
+
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_BFLOAT16_H
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 97c0daf79c546..184cc802d094d 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -66,4 +66,11 @@ struct Float128 {
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
+static_assert(
+ LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::Float128>::value);
+static_assert(
+ LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::Float128>::value);
+
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
>From 0401cd8e29135e1746e6865957a9ff1d01400734 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 4 Jun 2026 22:16:53 +0530
Subject: [PATCH 12/51] testing with all types of constructor
---
libc/src/__support/FPUtil/float128.h | 31 ++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 184cc802d094d..cf1a1d2f59199 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -23,13 +23,36 @@ namespace fputil {
struct Float128 {
UInt128 bits;
- LIBC_INLINE Float128() = default;
+ LIBC_INLINE constexpr Float128() = default;
+ LIBC_INLINE constexpr Float128(const Float128 &) = default;
+ LIBC_INLINE constexpr Float128(Float128 &&) = default;
+ LIBC_INLINE constexpr Float128 &operator=(const Float128 &) = default;
+ LIBC_INLINE constexpr Float128 &operator=(Float128 &&) = default;
- template <typename T> LIBC_INLINE constexpr explicit Float128(T x) : bits(0) {
+ template <typename T>
+ LIBC_INLINE constexpr explicit Float128(T value)
+ : bits(static_cast<UInt128>(0U)) {
if constexpr (cpp::is_floating_point_v<T>) {
- bits = fputil::cast<Float128>(x).bits;
+ bits = fputil::cast<Float128>(value).bits;
+ } else if constexpr (cpp::is_integral_v<T>) {
+ Sign sign = Sign::POS;
+
+ if constexpr (cpp::is_signed_v<T>) {
+ if (value < 0) {
+ sign = Sign::NEG;
+ value = -value;
+ }
+ }
+
+ fputil::DyadicFloat<cpp::numeric_limits<cpp::make_unsigned_t<T>>::digits>
+ xd(sign, 0, value);
+ bits = xd.template as<Float128, /*ShouldSignalExceptions=*/true>().bits;
+
+ } else if constexpr (cpp::is_convertible_v<T, Float128>) {
+ bits = value.operator Float128().bits;
+ } else {
+ bits = fputil::cast<Float128>(static_cast<float>(value)).bits;
}
- // TODO: add rem after testing
}
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T> &&
>From f9b330d58da4fa67cdbd1422c88617ae5076889e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 4 Jun 2026 22:24:42 +0530
Subject: [PATCH 13/51] removing constexpr
---
libc/src/__support/FPUtil/float128.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index cf1a1d2f59199..e8cccd019d0ea 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -23,7 +23,7 @@ namespace fputil {
struct Float128 {
UInt128 bits;
- LIBC_INLINE constexpr Float128() = default;
+ LIBC_INLINE Float128() = default;
LIBC_INLINE constexpr Float128(const Float128 &) = default;
LIBC_INLINE constexpr Float128(Float128 &&) = default;
LIBC_INLINE constexpr Float128 &operator=(const Float128 &) = default;
>From c92af9015d7b42347fba76e96651fc522ad923e2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 11 Jun 2026 18:11:24 +0530
Subject: [PATCH 14/51] nits before final (Win fail)
---
libc/src/__support/CPP/type_traits/is_floating_point.h | 2 ++
libc/src/__support/FPUtil/bfloat16.h | 2 ++
libc/src/__support/FPUtil/float128.h | 3 ++-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index d53dcd4961ab6..b7fa71bde2f93 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -40,6 +40,8 @@ template <typename T> struct is_floating_point {
bfloat16
,
+ // TODO: Replace as float128 once the alias is
+ // fixed
fputil::Float128>();
};
template <typename T>
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index cf3fefe75bff3..8a3f3c9894aad 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -135,11 +135,13 @@ struct BFloat16 {
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
+// <--To be removed------------------------------------>
static_assert(
LIBC_NAMESPACE::cpp::is_trivially_constructible<
LIBC_NAMESPACE::fputil::BFloat16>::value);
static_assert(
LIBC_NAMESPACE::cpp::is_trivially_copyable<
LIBC_NAMESPACE::fputil::BFloat16>::value);
+// ----------------------------------------------------
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_BFLOAT16_H
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index e8cccd019d0ea..df1e3e5e884a7 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -89,11 +89,12 @@ struct Float128 {
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
+// <--To be removed------------------------------------>
static_assert(
LIBC_NAMESPACE::cpp::is_trivially_constructible<
LIBC_NAMESPACE::fputil::Float128>::value);
static_assert(
LIBC_NAMESPACE::cpp::is_trivially_copyable<
LIBC_NAMESPACE::fputil::Float128>::value);
-
+// ----------------------------------------------------
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
>From c867385caf176740fd1d251483a13478c63c2a5e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 11 Jun 2026 20:16:12 +0530
Subject: [PATCH 15/51] testing CI for more operators and conversions (
floating-type)
---
libc/src/__support/FPUtil/float128.h | 42 ++++++++++++++++++----
libc/test/src/math/smoke/float128_test.cpp | 16 ++++++++-
2 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index df1e3e5e884a7..663d54a8de01e 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -16,6 +16,11 @@
#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
#include <stdint.h>
+#include "hdr/stdint_proxy.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/FPUtil/generic/mul.h"
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
@@ -29,6 +34,7 @@ struct Float128 {
LIBC_INLINE constexpr Float128 &operator=(const Float128 &) = default;
LIBC_INLINE constexpr Float128 &operator=(Float128 &&) = default;
+ // Floating point type and integer type
template <typename T>
LIBC_INLINE constexpr explicit Float128(T value)
: bits(static_cast<UInt128>(0U)) {
@@ -61,27 +67,51 @@ struct Float128 {
LIBC_INLINE LIBC_CONSTEXPR_DEFAULT operator T() const {
return fputil::cast<T>(*this);
}
- LIBC_INLINE constexpr bool operator==(Float128 &other) const {
+// TODO: Integer conversion
+ // unary
+ LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR Float128 operator-() const {
+ fputil::FPBits<Float128> result(*this);
+ result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
+ return result.get_val();
+ }
+ // operator overloads
+ LIBC_INLINE constexpr Float128 operator+(const Float128 &other) const {
+ return fputil::generic::add<Float128>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float128 operator-(const Float128 &other) const {
+ return fputil::generic::sub<Float128>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float128 operator*(const Float128 &other) const {
+ return fputil::generic::mul<Float128>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float128 operator/(const Float128 &other) const {
+ return fputil::generic::div<Float128>(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator==(const Float128 &other) const {
return fputil::equals(*this, other);
}
- LIBC_INLINE constexpr bool operator!=(Float128 &other) const {
+ LIBC_INLINE constexpr bool operator!=(const Float128 &other) const {
return !fputil::equals(*this, other);
}
- LIBC_INLINE constexpr bool operator<(Float128 &other) const {
+ LIBC_INLINE constexpr bool operator<(const Float128 &other) const {
return fputil::less_than(*this, other);
}
- LIBC_INLINE constexpr bool operator<=(Float128 &other) const {
+ LIBC_INLINE constexpr bool operator<=(const Float128 &other) const {
return fputil::less_than_or_equals(*this, other);
}
- LIBC_INLINE constexpr bool operator>(Float128 &other) const {
+ LIBC_INLINE constexpr bool operator>(const Float128 &other) const {
return fputil::greater_than(*this, other);
}
- LIBC_INLINE constexpr bool operator>=(Float128 &other) const {
+ LIBC_INLINE constexpr bool operator>=(const Float128 &other) const {
return fputil::greater_than_or_equals(*this, other);
}
};
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index f2f6d31007754..1a3a9a6c45726 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -17,15 +17,29 @@ TEST(LlvmLibcFloat128Test, DefaultConstructor) {
(void)x;
}
-TEST(LlvmLibcFloat128Test, operators) {
+TEST(LlvmLibcFloat128Test, UnaryOperators) {
Float128 a(1.0f), b(1.0f), c(2.0f);
// comparison operators
ASSERT_TRUE(a == b);
+ ASSERT_TRUE(a == Float128(1.0));
ASSERT_TRUE(a != c);
ASSERT_TRUE(b != c);
ASSERT_TRUE(c > b);
ASSERT_TRUE(a >= b);
ASSERT_TRUE(b <= c);
ASSERT_TRUE(a < c);
+
+ //negation
+ Float128 pa(1.0),na(-1.0f);
+ ASSERT_TRUE(-pa == na);
+ ASSERT_TRUE(-(-pa)== -na);
+}
+
+TEST(LlvmLibcFloat128Test, BinaryOperators) {
+ Float128 a(1.0f), b(1.0f), c(2.0f), d(3.0);
+ ASSERT_TRUE((a + b) == c);
+ ASSERT_TRUE((a - b) == Float128(0.0));
+ ASSERT_TRUE((c * d) == Float128(6.0));
+ ASSERT_TRUE((Float128(6.0) / d) == Float128(2.0));
}
>From bc1fd7a21e819b423eff0f7cb65cc9843f34faf9 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 11 Jun 2026 20:57:53 +0530
Subject: [PATCH 16/51] testing float128 add_sub addition
---
libc/src/__support/FPUtil/generic/add_sub.h | 10 +++++++++-
libc/test/src/math/smoke/float128_test.cpp | 18 +++++++++---------
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index cf662d051c162..0a2208f43cf05 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -116,7 +116,15 @@ add_or_sub(InType x, InType y) {
if constexpr (IsSub)
out_y_bits.set_sign(out_y_bits.sign().negate());
return out_y_bits.get_val();
- } else {
+ }
+ else if constexpr (cpp::is_same_v<InType, Float128> &&
+ cpp::is_same_v<OutType, Float128>) {
+ OutFPBits out_y_bits(y);
+ if constexpr (IsSub)
+ out_y_bits.set_sign(out_y_bits.sign().negate());
+ return out_y_bits.get_val();
+ }
+ else {
#ifdef LIBC_USE_CONSTEXPR
InType tmp = y;
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index 1a3a9a6c45726..41323bccb3467 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -22,7 +22,7 @@ TEST(LlvmLibcFloat128Test, UnaryOperators) {
// comparison operators
ASSERT_TRUE(a == b);
- ASSERT_TRUE(a == Float128(1.0));
+ // ASSERT_TRUE(a == Float128(1.0));
ASSERT_TRUE(a != c);
ASSERT_TRUE(b != c);
ASSERT_TRUE(c > b);
@@ -30,16 +30,16 @@ TEST(LlvmLibcFloat128Test, UnaryOperators) {
ASSERT_TRUE(b <= c);
ASSERT_TRUE(a < c);
- //negation
- Float128 pa(1.0),na(-1.0f);
- ASSERT_TRUE(-pa == na);
- ASSERT_TRUE(-(-pa)== -na);
+ // //negation
+ // Float128 pa(1.0),na(-1.0f);
+ // ASSERT_TRUE(-pa == na);
+ // ASSERT_TRUE(-(-pa)== -na);
}
TEST(LlvmLibcFloat128Test, BinaryOperators) {
- Float128 a(1.0f), b(1.0f), c(2.0f), d(3.0);
+ Float128 a(1.0f), b(1.0f), c(2.0f), d(3.0f);
ASSERT_TRUE((a + b) == c);
- ASSERT_TRUE((a - b) == Float128(0.0));
- ASSERT_TRUE((c * d) == Float128(6.0));
- ASSERT_TRUE((Float128(6.0) / d) == Float128(2.0));
+ ASSERT_TRUE((a - b) == Float128(0.0f));
+ ASSERT_TRUE((c * d) == Float128(6.0f));
+ ASSERT_TRUE((Float128(6.0f) / d) == Float128(2.0f));
}
>From 1c38cb9e687528d32000797e2ae9af0b880017ba Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 11 Jun 2026 20:59:53 +0530
Subject: [PATCH 17/51] testing intype = outType
---
libc/src/__support/FPUtil/generic/add_sub.h | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index 0a2208f43cf05..729b4afc9afca 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -110,15 +110,7 @@ add_or_sub(InType x, InType y) {
#endif // LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
}
- if constexpr (cpp::is_same_v<InType, bfloat16> &&
- cpp::is_same_v<OutType, bfloat16>) {
- OutFPBits out_y_bits(y);
- if constexpr (IsSub)
- out_y_bits.set_sign(out_y_bits.sign().negate());
- return out_y_bits.get_val();
- }
- else if constexpr (cpp::is_same_v<InType, Float128> &&
- cpp::is_same_v<OutType, Float128>) {
+ if constexpr (cpp::is_same_v<InType, OutType>) {
OutFPBits out_y_bits(y);
if constexpr (IsSub)
out_y_bits.set_sign(out_y_bits.sign().negate());
>From 6b65ee433a4742c8d638f7a57a6282b86047b1dc Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 11 Jun 2026 21:08:11 +0530
Subject: [PATCH 18/51] removed checker for LIBC_USE_CONSTEXPR
---
libc/src/__support/FPUtil/generic/add_sub.h | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index 729b4afc9afca..bdec242f4a591 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -115,17 +115,11 @@ add_or_sub(InType x, InType y) {
if constexpr (IsSub)
out_y_bits.set_sign(out_y_bits.sign().negate());
return out_y_bits.get_val();
- }
- else {
-
-#ifdef LIBC_USE_CONSTEXPR
- InType tmp = y;
-#else
+ } else {
// volatile prevents Clang from converting tmp to OutType and then
// immediately back to InType before negating it, resulting in double
// rounding.
volatile InType tmp = y;
-#endif // LIBC_USE_CONSTEXPR
if constexpr (IsSub)
tmp = -tmp;
return cast<OutType>(tmp);
>From 8a528f565dafb1235fc640e5756df097d97e4498 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 18 Jun 2026 18:39:29 +0530
Subject: [PATCH 19/51] int conversion + tests
temporary tests
clang-format
int conversion testing
---
libc/src/__support/FPUtil/bfloat16.h | 10 ++--
libc/src/__support/FPUtil/float128.h | 57 ++++++++++++++++------
libc/test/src/math/smoke/float128_test.cpp | 36 +++++++++++++-
3 files changed, 82 insertions(+), 21 deletions(-)
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index 8a3f3c9894aad..d7889843ac736 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -136,12 +136,10 @@ struct BFloat16 {
} // namespace LIBC_NAMESPACE_DECL
// <--To be removed------------------------------------>
-static_assert(
- LIBC_NAMESPACE::cpp::is_trivially_constructible<
- LIBC_NAMESPACE::fputil::BFloat16>::value);
-static_assert(
- LIBC_NAMESPACE::cpp::is_trivially_copyable<
- LIBC_NAMESPACE::fputil::BFloat16>::value);
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::BFloat16>::value);
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::BFloat16>::value);
// ----------------------------------------------------
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_BFLOAT16_H
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 663d54a8de01e..642e348220a29 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -9,18 +9,18 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
+#include "hdr/stdint_proxy.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/cast.h"
#include "src/__support/FPUtil/comparison_operations.h"
-#include "src/__support/macros/attributes.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/uint128.h"
-#include <stdint.h>
-#include "hdr/stdint_proxy.h"
#include "src/__support/FPUtil/dyadic_float.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/uint128.h"
+#include <stdint.h>
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
@@ -34,7 +34,7 @@ struct Float128 {
LIBC_INLINE constexpr Float128 &operator=(const Float128 &) = default;
LIBC_INLINE constexpr Float128 &operator=(Float128 &&) = default;
- // Floating point type and integer type
+ // Floating point type and integer type
template <typename T>
LIBC_INLINE constexpr explicit Float128(T value)
: bits(static_cast<UInt128>(0U)) {
@@ -67,7 +67,21 @@ struct Float128 {
LIBC_INLINE LIBC_CONSTEXPR_DEFAULT operator T() const {
return fputil::cast<T>(*this);
}
-// TODO: Integer conversion
+
+ // Integer conversion (Incomplete + not verified with tests)
+ template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
+ LIBC_INLINE constexpr explicit operator T() const {
+ fputil::FPBits<Float128> x_bits(*this);
+ if (x_bits.is_zero())
+ return static_cast<T>(0);
+
+ fputil::DyadicFloat<fputil::FPBits<Float128>::STORAGE_LEN> xd(
+ x_bits.sign(),
+ x_bits.get_explicit_exponent() - fputil::FPBits<Float128>::FRACTION_LEN,
+ x_bits.get_explicit_mantissa());
+ return static_cast<T>(xd.as_mantissa_type_rounded());
+ }
+
// unary
LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR Float128 operator-() const {
fputil::FPBits<Float128> result(*this);
@@ -75,7 +89,7 @@ struct Float128 {
return result.get_val();
}
// operator overloads
- LIBC_INLINE constexpr Float128 operator+(const Float128 &other) const {
+ LIBC_INLINE constexpr Float128 operator+(const Float128 &other) const {
return fputil::generic::add<Float128>(*this, other);
}
@@ -114,17 +128,32 @@ struct Float128 {
LIBC_INLINE constexpr bool operator>=(const Float128 &other) const {
return fputil::greater_than_or_equals(*this, other);
}
+
+ LIBC_INLINE constexpr Float128 &operator*=(const Float128 &other) {
+ *this = *this * other;
+ return *this;
+ }
+ LIBC_INLINE constexpr Float128 &operator+=(const Float128 &other) {
+ *this = *this + other;
+ return *this;
+ }
+ LIBC_INLINE constexpr Float128 &operator-=(const Float128 &other) {
+ *this = *this - other;
+ return *this;
+ }
+ LIBC_INLINE constexpr Float128 &operator/=(const Float128 &other) {
+ *this = *this / other;
+ return *this;
+ }
};
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
// <--To be removed------------------------------------>
-static_assert(
- LIBC_NAMESPACE::cpp::is_trivially_constructible<
- LIBC_NAMESPACE::fputil::Float128>::value);
-static_assert(
- LIBC_NAMESPACE::cpp::is_trivially_copyable<
- LIBC_NAMESPACE::fputil::Float128>::value);
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::Float128>::value);
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::Float128>::value);
// ----------------------------------------------------
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index 41323bccb3467..0e4126edd91be 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -30,7 +30,7 @@ TEST(LlvmLibcFloat128Test, UnaryOperators) {
ASSERT_TRUE(b <= c);
ASSERT_TRUE(a < c);
- // //negation
+ // //negation
// Float128 pa(1.0),na(-1.0f);
// ASSERT_TRUE(-pa == na);
// ASSERT_TRUE(-(-pa)== -na);
@@ -43,3 +43,37 @@ TEST(LlvmLibcFloat128Test, BinaryOperators) {
ASSERT_TRUE((c * d) == Float128(6.0f));
ASSERT_TRUE((Float128(6.0f) / d) == Float128(2.0f));
}
+
+TEST(LlvmLibcFloat128Test, Negation) {
+ Float128 pa(1.0f), na(-1.0f);
+ ASSERT_TRUE(-pa == na);
+ ASSERT_TRUE(-(-pa) == pa);
+ ASSERT_TRUE(-na == pa);
+}
+
+TEST(LlvmLibcFloat128Test, CompoundAssignment) {
+ Float128 a(1.0f), b(2.0f), c(3.0f), d(4.0f);
+
+ a += Float128(2.0f);
+ ASSERT_TRUE(a == c);
+
+ b -= Float128(1.0f);
+ ASSERT_TRUE(b == Float128(1.0f));
+
+ c *= Float128(2.0f);
+ ASSERT_TRUE(c == Float128(6.0f));
+
+ d /= Float128(2.0f);
+ ASSERT_TRUE(d == Float128(2.0f));
+}
+
+TEST(LlvmLibcFloat128Test, IntegerConversion) {
+ ASSERT_EQ(static_cast<int>(Float128(0.0f)), 0);
+ ASSERT_EQ(static_cast<int>(Float128(1.0f)), 1);
+ ASSERT_EQ(static_cast<int>(Float128(-1.0f)), -1);
+ ASSERT_EQ(static_cast<int>(Float128(42.0f)), 42);
+ ASSERT_EQ(static_cast<int>(Float128(-42.0f)), -42);
+ ASSERT_EQ(static_cast<long long>(Float128(123456789.0)),
+ static_cast<long long>(123456789));
+ ASSERT_EQ(static_cast<unsigned>(Float128(7.0f)), 7U);
+}
>From d3b5fee4bab73436cf23d973ab6ef1795a72a215 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 18 Jun 2026 19:41:55 +0530
Subject: [PATCH 20/51] int conversion
---
libc/src/__support/FPUtil/float128.h | 11 +++++------
libc/test/src/math/smoke/float128_test.cpp | 2 +-
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 642e348220a29..8f50df91f2486 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -71,13 +71,12 @@ struct Float128 {
// Integer conversion (Incomplete + not verified with tests)
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
LIBC_INLINE constexpr explicit operator T() const {
- fputil::FPBits<Float128> x_bits(*this);
- if (x_bits.is_zero())
- return static_cast<T>(0);
-
- fputil::DyadicFloat<fputil::FPBits<Float128>::STORAGE_LEN> xd(
+ FPBits<Float128> x_bits(*this);
+ int x_bits_exp = x_bits.get_explicit_exponent() - FPBits<Float128>::FRACTION_LEN;
+ // sign * mantissa * 2(exp-bias)
+ DyadicFloat<FPBits<Float128>::STORAGE_LEN> xd(
x_bits.sign(),
- x_bits.get_explicit_exponent() - fputil::FPBits<Float128>::FRACTION_LEN,
+ x_bits_exp,
x_bits.get_explicit_mantissa());
return static_cast<T>(xd.as_mantissa_type_rounded());
}
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index 0e4126edd91be..0ebcce3248c1f 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -18,7 +18,7 @@ TEST(LlvmLibcFloat128Test, DefaultConstructor) {
}
TEST(LlvmLibcFloat128Test, UnaryOperators) {
- Float128 a(1.0f), b(1.0f), c(2.0f);
+ Float128 a(1.0), b(1.0f), c(2.0f);
// comparison operators
ASSERT_TRUE(a == b);
>From b1e0c6c81daa29c485d1d38adebf5b4b269b20b9 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 19 Jun 2026 03:22:56 +0530
Subject: [PATCH 21/51] cleanup and tests
fix for test fails
clang format
cleanup for test
---
libc/src/__support/FPUtil/bfloat16.h | 7 --
libc/src/__support/FPUtil/float128.h | 12 +--
libc/src/__support/FPUtil/generic/add_sub.h | 6 ++
libc/test/src/__support/FPUtil/CMakeLists.txt | 11 +++
.../src/__support/FPUtil/float128_test.cpp | 91 +++++++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 10 --
libc/test/src/math/smoke/float128_test.cpp | 79 ----------------
7 files changed, 110 insertions(+), 106 deletions(-)
create mode 100644 libc/test/src/__support/FPUtil/float128_test.cpp
delete mode 100644 libc/test/src/math/smoke/float128_test.cpp
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index d7889843ac736..ce4e3160a0963 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -135,11 +135,4 @@ struct BFloat16 {
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
-// <--To be removed------------------------------------>
-static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
- LIBC_NAMESPACE::fputil::BFloat16>::value);
-static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
- LIBC_NAMESPACE::fputil::BFloat16>::value);
-// ----------------------------------------------------
-
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_BFLOAT16_H
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 8f50df91f2486..9fdd47bb48597 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -50,8 +50,7 @@ struct Float128 {
}
}
- fputil::DyadicFloat<cpp::numeric_limits<cpp::make_unsigned_t<T>>::digits>
- xd(sign, 0, value);
+ fputil::DyadicFloat<FPBits<Float128>::STORAGE_LEN> xd(sign, 0, value);
bits = xd.template as<Float128, /*ShouldSignalExceptions=*/true>().bits;
} else if constexpr (cpp::is_convertible_v<T, Float128>) {
@@ -68,7 +67,6 @@ struct Float128 {
return fputil::cast<T>(*this);
}
- // Integer conversion (Incomplete + not verified with tests)
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
LIBC_INLINE constexpr explicit operator T() const {
FPBits<Float128> x_bits(*this);
@@ -78,7 +76,7 @@ struct Float128 {
x_bits.sign(),
x_bits_exp,
x_bits.get_explicit_mantissa());
- return static_cast<T>(xd.as_mantissa_type_rounded());
+ return static_cast<T>(xd.as_mantissa_type());
}
// unary
@@ -149,10 +147,4 @@ struct Float128 {
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
-// <--To be removed------------------------------------>
-static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
- LIBC_NAMESPACE::fputil::Float128>::value);
-static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
- LIBC_NAMESPACE::fputil::Float128>::value);
-// ----------------------------------------------------
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
diff --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index bdec242f4a591..71e50daa9a996 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -116,10 +116,16 @@ add_or_sub(InType x, InType y) {
out_y_bits.set_sign(out_y_bits.sign().negate());
return out_y_bits.get_val();
} else {
+
+#ifdef LIBC_USE_CONSTEXPR
+ InType tmp = y;
+#else
// volatile prevents Clang from converting tmp to OutType and then
// immediately back to InType before negating it, resulting in double
// rounding.
volatile InType tmp = y;
+#endif // LIBC_USE_CONSTEXPR
+
if constexpr (IsSub)
tmp = -tmp;
return cast<OutType>(tmp);
diff --git a/libc/test/src/__support/FPUtil/CMakeLists.txt b/libc/test/src/__support/FPUtil/CMakeLists.txt
index 81db4ccae44c6..e38c9bcdc9fcd 100644
--- a/libc/test/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/test/src/__support/FPUtil/CMakeLists.txt
@@ -39,6 +39,17 @@ add_fp_unittest(
libc.src.__support.FPUtil.rounding_mode
)
+add_libc_test(
+ float128_test
+ SUITE
+ libc-fputil-tests
+ SRCS
+ float128_test.cpp
+ DEPENDS
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.uint128
+)
+
# TODO: Temporally disable bfloat16 test until MPCommon target is updated
# https://github.com/llvm/llvm-project/pull/149678
if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/test/src/__support/FPUtil/float128_test.cpp b/libc/test/src/__support/FPUtil/float128_test.cpp
new file mode 100644
index 0000000000000..31d852c0c9bab
--- /dev/null
+++ b/libc/test/src/__support/FPUtil/float128_test.cpp
@@ -0,0 +1,91 @@
+//===-- Unittests for Float128 emulated type -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/float128.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::Sign;
+using LIBC_NAMESPACE::fputil::Float128;
+
+TEST(LlvmLibcFloat128Test, Operators) {
+ Float128 a(1.0f), b(1.0f), c(2.0f), d(3.0f), pa(1.0f), na(-1.0f);
+
+ // comparison operators
+ ASSERT_TRUE(a == b);
+ ASSERT_TRUE(a == Float128(1.0));
+ ASSERT_TRUE(a != c);
+ ASSERT_TRUE(b != c);
+ ASSERT_TRUE(c > b);
+ ASSERT_TRUE(a >= b);
+ ASSERT_TRUE(b <= c);
+ ASSERT_TRUE(a < c);
+
+ // Unary operators
+ ASSERT_TRUE(-pa == na);
+ ASSERT_TRUE(-(-pa) == pa);
+
+ // Binary operators
+ ASSERT_TRUE((a + b) == c);
+ ASSERT_TRUE((a - b) == Float128(0.0f));
+ ASSERT_TRUE((c * d) == Float128(6.0f));
+ ASSERT_TRUE((Float128(6.0f) / d) == Float128(2.0f));
+
+ // Compound assignment operators
+ a += Float128(1.0f);
+ ASSERT_TRUE(a == c);
+ b -= Float128(1.0f);
+ ASSERT_TRUE(b == Float128(0.0f));
+ c *= Float128(2.0f);
+ ASSERT_TRUE(c == Float128(4.0f));
+ d /= Float128(3.0f);
+ ASSERT_TRUE(d == Float128(1.0f));
+}
+
+TEST(LlvmLibcFloat128Test, SpecialValues) {
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float128>;
+
+ Float128 zero = FPBits::zero(Sign::POS).get_val();
+ Float128 neg_zero = FPBits::zero(Sign::NEG).get_val();
+ Float128 inf = FPBits::inf(Sign::POS).get_val();
+ Float128 neg_inf = FPBits::inf(Sign::NEG).get_val();
+ Float128 nan = FPBits::quiet_nan().get_val();
+
+ // checking operators with special values
+ ASSERT_TRUE(zero == neg_zero); // +0.0 == -0.0 is true
+ ASSERT_TRUE(zero == Float128(0.0f));
+ ASSERT_TRUE(inf == inf);
+ ASSERT_TRUE(-inf == neg_inf);
+ ASSERT_TRUE((inf + Float128(1.0f)) == inf);
+ ASSERT_TRUE(inf + inf == inf);
+ ASSERT_TRUE(nan != nan);
+ ASSERT_TRUE(!(nan == nan));
+ ASSERT_TRUE(nan != zero);
+}
+
+TEST(LlvmLibcFloat128Test, IntegerConversion) {
+ // Float128 to Integer conversion test
+ ASSERT_EQ(static_cast<int>(Float128(0.0f)), 0);
+ ASSERT_EQ(static_cast<int>(Float128(1.0f)), 1);
+ ASSERT_EQ(static_cast<int>(Float128(-1.0)), -1);
+ ASSERT_EQ(static_cast<long long>(Float128(1000000000.0)),
+ static_cast<long long>(1000000000));
+ ASSERT_EQ(static_cast<unsigned>(Float128(7.0f)), 7U);
+ ASSERT_EQ(static_cast<int>(Float128(-1.5)), -1);
+ ASSERT_EQ(static_cast<int>(Float128(-1.9)), -1);
+ ASSERT_EQ(static_cast<int>(Float128(1.9f)), 1);
+}
+
+TEST(LlvmLibcFloat128Test, FromIntegralTypes) {
+ // Integer to float128 conversion test
+ ASSERT_TRUE(Float128(42) == Float128(42.0f));
+ ASSERT_TRUE(Float128(-42) == Float128(-42.0f));
+ ASSERT_TRUE(Float128(0) == Float128(0.0f));
+ ASSERT_TRUE(Float128(7U) == Float128(7.0f));
+ ASSERT_TRUE(Float128(-7LL) == Float128(-7.0));
+ ASSERT_TRUE(Float128(123456789LL) == Float128(123456789.0));
+}
\ No newline at end of file
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 3081a62552c49..e4e2fb11438d4 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1,16 +1,6 @@
add_custom_target(libc-math-smoke-tests)
add_dependencies(libc-math-unittests libc-math-smoke-tests)
-add_libc_unittest(
- float128_test
- SUITE
- libc-math-smoke-tests
- SRCS
- float128_test.cpp
- DEPENDS
- libc.src.__support.FPUtil.float128
-)
-
add_fp_unittest(
cosf_test
SUITE
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
deleted file mode 100644
index 0ebcce3248c1f..0000000000000
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-//===-- Unittests for Float128 emulated type -----------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/__support/FPUtil/float128.h"
-#include "src/__support/uint128.h"
-#include "test/UnitTest/Test.h"
-
-using LIBC_NAMESPACE::fputil::Float128;
-
-TEST(LlvmLibcFloat128Test, DefaultConstructor) {
- Float128 x;
- (void)x;
-}
-
-TEST(LlvmLibcFloat128Test, UnaryOperators) {
- Float128 a(1.0), b(1.0f), c(2.0f);
-
- // comparison operators
- ASSERT_TRUE(a == b);
- // ASSERT_TRUE(a == Float128(1.0));
- ASSERT_TRUE(a != c);
- ASSERT_TRUE(b != c);
- ASSERT_TRUE(c > b);
- ASSERT_TRUE(a >= b);
- ASSERT_TRUE(b <= c);
- ASSERT_TRUE(a < c);
-
- // //negation
- // Float128 pa(1.0),na(-1.0f);
- // ASSERT_TRUE(-pa == na);
- // ASSERT_TRUE(-(-pa)== -na);
-}
-
-TEST(LlvmLibcFloat128Test, BinaryOperators) {
- Float128 a(1.0f), b(1.0f), c(2.0f), d(3.0f);
- ASSERT_TRUE((a + b) == c);
- ASSERT_TRUE((a - b) == Float128(0.0f));
- ASSERT_TRUE((c * d) == Float128(6.0f));
- ASSERT_TRUE((Float128(6.0f) / d) == Float128(2.0f));
-}
-
-TEST(LlvmLibcFloat128Test, Negation) {
- Float128 pa(1.0f), na(-1.0f);
- ASSERT_TRUE(-pa == na);
- ASSERT_TRUE(-(-pa) == pa);
- ASSERT_TRUE(-na == pa);
-}
-
-TEST(LlvmLibcFloat128Test, CompoundAssignment) {
- Float128 a(1.0f), b(2.0f), c(3.0f), d(4.0f);
-
- a += Float128(2.0f);
- ASSERT_TRUE(a == c);
-
- b -= Float128(1.0f);
- ASSERT_TRUE(b == Float128(1.0f));
-
- c *= Float128(2.0f);
- ASSERT_TRUE(c == Float128(6.0f));
-
- d /= Float128(2.0f);
- ASSERT_TRUE(d == Float128(2.0f));
-}
-
-TEST(LlvmLibcFloat128Test, IntegerConversion) {
- ASSERT_EQ(static_cast<int>(Float128(0.0f)), 0);
- ASSERT_EQ(static_cast<int>(Float128(1.0f)), 1);
- ASSERT_EQ(static_cast<int>(Float128(-1.0f)), -1);
- ASSERT_EQ(static_cast<int>(Float128(42.0f)), 42);
- ASSERT_EQ(static_cast<int>(Float128(-42.0f)), -42);
- ASSERT_EQ(static_cast<long long>(Float128(123456789.0)),
- static_cast<long long>(123456789));
- ASSERT_EQ(static_cast<unsigned>(Float128(7.0f)), 7U);
-}
>From 40f97218972bdebd600c1f743ea18f7f23c2d8d2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 24 Jun 2026 20:54:08 +0530
Subject: [PATCH 22/51] use IEEE754_Binary128 as the container
---
libc/src/__support/FPUtil/FPBits.h | 13 ++-----------
libc/test/src/__support/FPUtil/float128_test.cpp | 2 +-
2 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 5b7461a44cff5..83219b7573f46 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -37,8 +37,7 @@ enum class FPType {
IEEE754_Binary64,
IEEE754_Binary128,
X86_Binary80,
- BFloat16,
- Float128
+ BFloat16
};
// The classes hierarchy is as follows:
@@ -147,14 +146,6 @@ template <> struct FPLayout<FPType::BFloat16> {
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
};
-template <> struct FPLayout<FPType::Float128> {
- using StorageType = UInt128;
- LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
- LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
- LIBC_INLINE_VAR static constexpr int SIG_LEN = 112;
- LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
-};
-
// FPStorage derives useful constants from the FPLayout above.
template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
using UP = FPLayout<fp_type>;
@@ -823,7 +814,7 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
else if constexpr (cpp::is_same_v<UnqualT, bfloat16>)
return FPType::BFloat16;
else if constexpr (cpp::is_same_v<UnqualT, Float128>)
- return FPType::Float128;
+ return FPType::IEEE754_Binary128;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
}
diff --git a/libc/test/src/__support/FPUtil/float128_test.cpp b/libc/test/src/__support/FPUtil/float128_test.cpp
index 31d852c0c9bab..de37226034ddd 100644
--- a/libc/test/src/__support/FPUtil/float128_test.cpp
+++ b/libc/test/src/__support/FPUtil/float128_test.cpp
@@ -88,4 +88,4 @@ TEST(LlvmLibcFloat128Test, FromIntegralTypes) {
ASSERT_TRUE(Float128(7U) == Float128(7.0f));
ASSERT_TRUE(Float128(-7LL) == Float128(-7.0));
ASSERT_TRUE(Float128(123456789LL) == Float128(123456789.0));
-}
\ No newline at end of file
+}
>From 365e9b1a45b4c26539bf637cdbb6e4f5c3de2f48 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 24 Jun 2026 21:13:01 +0530
Subject: [PATCH 23/51] clang-format
---
libc/src/__support/FPUtil/float128.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 9fdd47bb48597..50a0f93cbd297 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -70,12 +70,11 @@ struct Float128 {
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
LIBC_INLINE constexpr explicit operator T() const {
FPBits<Float128> x_bits(*this);
- int x_bits_exp = x_bits.get_explicit_exponent() - FPBits<Float128>::FRACTION_LEN;
+ int x_bits_exp =
+ x_bits.get_explicit_exponent() - FPBits<Float128>::FRACTION_LEN;
// sign * mantissa * 2(exp-bias)
DyadicFloat<FPBits<Float128>::STORAGE_LEN> xd(
- x_bits.sign(),
- x_bits_exp,
- x_bits.get_explicit_mantissa());
+ x_bits.sign(), x_bits_exp, x_bits.get_explicit_mantissa());
return static_cast<T>(xd.as_mantissa_type());
}
>From b2c413b8d32ae282fe82184164566b2abe1f5290 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 24 Jun 2026 21:18:43 +0530
Subject: [PATCH 24/51] 1:1 dependency
---
libc/src/__support/FPUtil/CMakeLists.txt | 11 ++++++++---
libc/src/__support/FPUtil/float128.h | 1 -
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index c49d873b026e2..8b6ac8027b52d 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -299,12 +299,17 @@ add_header_library(
HDRS
float128.h
DEPENDS
- libc.src.__support.CPP.bit
+ .cast
+ .comparison_operations
+ .dyadic_float
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.FPUtil.generic.div
+ libc.src.__support.FPUtil.generic.mul
libc.src.__support.macros.attributes
libc.src.__support.macros.config
libc.src.__support.uint128
- libc.src.__support.CPP.type_traits
- .comparison_operations
)
add_subdirectory(generic)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 50a0f93cbd297..cbb113567dc05 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -20,7 +20,6 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
-#include <stdint.h>
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
>From 1dbbeeee17060164f03000082d39e4050242b956 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 25 Jun 2026 21:02:20 +0530
Subject: [PATCH 25/51] test: bigInt
---
libc/src/__support/FPUtil/float128.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index cbb113567dc05..025c8d2170256 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -141,7 +141,12 @@ struct Float128 {
return *this;
}
};
-
+static_assert(
+ LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::Float128>::value);
+static_assert(
+ LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::Float128>::value);
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
>From 8494d779431dd2d2d6daaa2f5439067b91ee4815 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 25 Jun 2026 21:19:04 +0530
Subject: [PATCH 26/51] force win
---
libc/src/__support/macros/properties/types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 7b861640c785d..43a8c43b596b1 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -42,7 +42,7 @@
#endif // UINT64_MAX
// int128 / uint128 support
-#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
+#if defined(__SIZEOF_INT128__)
#define LIBC_TYPES_HAS_INT128
#endif // defined(__SIZEOF_INT128__)
>From 5250f896e3bbf5bcd29210f19f23f1cf3ccf8fd8 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 25 Jun 2026 21:45:31 +0530
Subject: [PATCH 27/51] test: big_int Trivially const
---
libc/src/__support/macros/properties/types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 43a8c43b596b1..7b861640c785d 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -42,7 +42,7 @@
#endif // UINT64_MAX
// int128 / uint128 support
-#if defined(__SIZEOF_INT128__)
+#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
#define LIBC_TYPES_HAS_INT128
#endif // defined(__SIZEOF_INT128__)
>From 72da643cd2cffd72fd4e53da3c28c6da48527d03 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 28 Jun 2026 02:13:29 +0530
Subject: [PATCH 28/51] revert last change
---
libc/src/__support/big_int.h | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 29da5b9866bb0..4c81544562e00 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -358,7 +358,7 @@ struct BigInt {
LIBC_INLINE_VAR static constexpr size_t WORD_COUNT = Bits / WORD_SIZE;
- cpp::array<WordType, WORD_COUNT> val;
+ cpp::array<WordType, WORD_COUNT> val{}; // zero initialized.
LIBC_INLINE constexpr BigInt() = default;
@@ -1367,11 +1367,6 @@ first_trailing_one(T value) {
return value == 0 ? 0 : cpp::countr_zero(value) + 1;
}
-static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
- LIBC_NAMESPACE::BigInt<128, false>>::value);
-static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
- LIBC_NAMESPACE::BigInt<128, false>>::value);
-
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_BIG_INT_H
>From 0841a00e7277d8bed3cd164c5bedee343cc5c7d8 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 28 Jun 2026 23:15:11 +0530
Subject: [PATCH 29/51] test: braces
---
libc/src/__support/big_int.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 4c81544562e00..d0c1d6d07b742 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -358,7 +358,7 @@ struct BigInt {
LIBC_INLINE_VAR static constexpr size_t WORD_COUNT = Bits / WORD_SIZE;
- cpp::array<WordType, WORD_COUNT> val{}; // zero initialized.
+ cpp::array<WordType, WORD_COUNT> val; // zero initialized.
LIBC_INLINE constexpr BigInt() = default;
>From 5a8c69bbbd78f2ec70f637e085909c6e6552bf00 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 28 Jun 2026 23:48:34 +0530
Subject: [PATCH 30/51] clang-format
---
libc/src/__support/FPUtil/float128.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 025c8d2170256..661dfe808f8b2 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -141,12 +141,12 @@ struct Float128 {
return *this;
}
};
-static_assert(
- LIBC_NAMESPACE::cpp::is_trivially_constructible<
- LIBC_NAMESPACE::fputil::Float128>::value);
-static_assert(
- LIBC_NAMESPACE::cpp::is_trivially_copyable<
- LIBC_NAMESPACE::fputil::Float128>::value);
+
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::Float128>::value);
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::Float128>::value);
+
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
>From fbe5245571f7b6bc270e5ac5d59cc873c6dcc6c2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:04:39 +0530
Subject: [PATCH 31/51] update
---
libc/src/__support/big_int.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index d0c1d6d07b742..653b817e3dee7 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -358,7 +358,7 @@ struct BigInt {
LIBC_INLINE_VAR static constexpr size_t WORD_COUNT = Bits / WORD_SIZE;
- cpp::array<WordType, WORD_COUNT> val; // zero initialized.
+ cpp::array<WordType, WORD_COUNT> val;
LIBC_INLINE constexpr BigInt() = default;
>From d5433f14bbd08b9aca743197f958ce8c4e62c6da Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:00:33 +0530
Subject: [PATCH 32/51] test: emulated float128 with ceilf128
---
libc/shared/math/ceilf128.h | 9 +++------
libc/src/__support/math/ceilf128.h | 11 ++++-------
libc/src/math/ceilf128.h | 5 ++++-
libc/src/math/generic/ceilf128.cpp | 5 ++++-
libc/test/src/math/ceilf128_test.cpp | 5 ++++-
5 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/libc/shared/math/ceilf128.h b/libc/shared/math/ceilf128.h
index b9e6655393e14..25611636e2233 100644
--- a/libc/shared/math/ceilf128.h
+++ b/libc/shared/math/ceilf128.h
@@ -9,12 +9,11 @@
#ifndef LLVM_LIBC_SHARED_MATH_CEILF128_H
#define LLVM_LIBC_SHARED_MATH_CEILF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_FLOAT128
-
#include "shared/libc_common.h"
#include "src/__support/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace shared {
@@ -24,6 +23,4 @@ using math::ceilf128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_FLOAT128
-
#endif // LLVM_LIBC_SHARED_MATH_CEILF128_H
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 8877594d58d68..f12fc6a11a07c 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -9,21 +9,18 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_FLOAT128
-
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/macros/config.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr float128 ceilf128(float128 x) { return fputil::ceil(x); }
+LIBC_INLINE constexpr Float128 ceilf128(Float128 x) { return fputil::ceil(x); }
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_FLOAT128
-
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
diff --git a/libc/src/math/ceilf128.h b/libc/src/math/ceilf128.h
index 211b8131a9559..40de768feb299 100644
--- a/libc/src/math/ceilf128.h
+++ b/libc/src/math/ceilf128.h
@@ -11,10 +11,13 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
-float128 ceilf128(float128 x);
+Float128 ceilf128(Float128 x);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index fd9c206612207..e359ef9cb18b7 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -8,10 +8,13 @@
#include "src/math/ceilf128.h"
#include "src/__support/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
+LLVM_LIBC_FUNCTION(Float128, ceilf128, (Float128 x)) {
return math::ceilf128(x);
}
diff --git a/libc/test/src/math/ceilf128_test.cpp b/libc/test/src/math/ceilf128_test.cpp
index f0da8258f79bc..e01221f4ac6cd 100644
--- a/libc/test/src/math/ceilf128_test.cpp
+++ b/libc/test/src/math/ceilf128_test.cpp
@@ -9,5 +9,8 @@
#include "CeilTest.h"
#include "src/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
-LIST_CEIL_TESTS(float128, LIBC_NAMESPACE::ceilf128)
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
>From 7ede1979e6c4b60a8025523a60d4f83912718004 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:15:56 +0530
Subject: [PATCH 33/51] test: float128
---
libc/src/__support/math/ceilf128.h | 3 ---
libc/test/shared/shared_math_test.cpp | 11 ++++++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index f12fc6a11a07c..0361251b664a9 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -11,9 +11,6 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/macros/config.h"
-#include "src/__support/FPUtil/float128.h"
-
-using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace math {
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 8ae2aac3d51ed..165591594f45e 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -575,6 +575,16 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+// Emulated float128
+// TODO: style
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
+
+TEST(LlvmLibcSharedMathTest, AllEmuFloat128){
+ EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+}
+
#ifdef LIBC_TYPES_HAS_FLOAT128
TEST(LlvmLibcSharedMathTest, AllFloat128) {
@@ -620,7 +630,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divf128(
float128(4.0), float128(2.0)));
- EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::copysignf128(
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(float128(0.0),
>From ef8aee688942b2086bf7808353f53897caa01bdc Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:23:17 +0530
Subject: [PATCH 34/51] nit
---
libc/test/shared/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index aeb573474d6ef..07eaf80a6a0bb 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -17,6 +17,7 @@ add_fp_unittest(
SRCS
shared_math_test.cpp
DEPENDS
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.fp_bits
libc.src.__support.math.acos
libc.src.__support.math.acosbf16
>From 73c8a93d4745b42f5fb4b5c446d902a6ac94b65c Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:35:44 +0530
Subject: [PATCH 35/51] cmake edits
---
libc/src/__support/math/CMakeLists.txt | 2 +-
libc/src/__support/math/ceilf128.h | 3 +++
libc/src/math/generic/CMakeLists.txt | 1 +
libc/test/src/math/CMakeLists.txt | 1 +
libc/test/src/math/smoke/CMakeLists.txt | 1 +
libc/test/src/math/smoke/ceilf128_test.cpp | 5 ++++-
6 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index deafc85b487a6..a2699355a18e8 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -813,7 +813,7 @@ add_header_library(
HDRS
ceilf128.h
DEPENDS
- libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 0361251b664a9..d8d82970df7e7 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -11,7 +11,10 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/macros/config.h"
+#include "src/__support/FPUtil/float128.h"
+using LIBC_NAMESPACE::fputil::Float128;
+c
namespace LIBC_NAMESPACE_DECL {
namespace math {
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 28b708e0c8f7a..6769f4fdd4dcb 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -162,6 +162,7 @@ add_entrypoint_object(
../ceilf128.h
DEPENDS
libc.src.__support.math.ceilf128
+ libc.src.__support.FPUtil.float128
)
add_entrypoint_object(
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 4698f246fe4cc..c4944081bb2a2 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -424,6 +424,7 @@ add_fp_unittest(
libc.src.math.ceilf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.float128
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index e4e2fb11438d4..7876270493e11 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -607,6 +607,7 @@ add_fp_unittest(
CeilTest.h
DEPENDS
libc.src.math.ceilf128
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/smoke/ceilf128_test.cpp b/libc/test/src/math/smoke/ceilf128_test.cpp
index f0da8258f79bc..e01221f4ac6cd 100644
--- a/libc/test/src/math/smoke/ceilf128_test.cpp
+++ b/libc/test/src/math/smoke/ceilf128_test.cpp
@@ -9,5 +9,8 @@
#include "CeilTest.h"
#include "src/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
-LIST_CEIL_TESTS(float128, LIBC_NAMESPACE::ceilf128)
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
>From b31d779a810771d9dcc7dfea30eec4153aae6e6d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:41:00 +0530
Subject: [PATCH 36/51] nits
---
libc/src/__support/math/ceilf128.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index d8d82970df7e7..f12fc6a11a07c 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -14,7 +14,7 @@
#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
-c
+
namespace LIBC_NAMESPACE_DECL {
namespace math {
>From d4460c6a6360b2ec15b996b8a66b294de3767def Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:17:21 +0530
Subject: [PATCH 37/51] test mpfr
---
libc/utils/MPFRWrapper/CMakeLists.txt | 120 +++++++++++++-------------
libc/utils/MPFRWrapper/MPCommon.cpp | 7 ++
libc/utils/MPFRWrapper/MPCommon.h | 9 +-
3 files changed, 76 insertions(+), 60 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 73151c61a7fcc..a1324e9af33c9 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,59 +1,61 @@
-if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
- add_library(libcMPCommon STATIC
- MPCommon.cpp
- MPCommon.h
- mpfr_inc.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
- add_dependencies(
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.string
- libc.src.__support.CPP.string_view
- libc.src.__support.CPP.type_traits
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.cast
- libc.src.__support.FPUtil.fp_bits
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
-
-if(LIBC_TESTS_CAN_USE_MPFR)
- add_library(libcMPFRWrapper STATIC
- MPFRUtils.cpp
- MPFRUtils.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
- add_dependencies(
- libcMPFRWrapper
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.array
- libc.src.__support.CPP.stringstream
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.fpbits_str
- LibcTest.unit
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
+if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
+ add_library(libcMPCommon STATIC
+ MPCommon.cpp
+ MPCommon.h
+ mpfr_inc.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
+ add_dependencies(
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.string
+ libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.fp_bits
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
+
+if(LIBC_TESTS_CAN_USE_MPFR)
+ add_library(libcMPFRWrapper STATIC
+ MPFRUtils.cpp
+ MPFRUtils.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
+ add_dependencies(
+ libcMPFRWrapper
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.array
+ libc.src.__support.CPP.stringstream
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.fpbits_str
+ LibcTest.unit
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index 452a1391058d4..a636b091a15f8 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -13,6 +13,9 @@
#include "src/__support/FPUtil/cast.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace testing {
@@ -643,6 +646,10 @@ template <> bfloat16 MPFRNumber::as<bfloat16>() const {
return fputil::cast<bfloat16>(mpfr_get_flt(value, mpfr_rounding));
}
+template <> Float128 MPFRNumber::as<Float128>() const {
+ return fputil::cast<Float128>(mpfr_get_flt(value, mpfr_rounding));
+}
+
} // namespace mpfr
} // namespace testing
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 935a2614968a2..56b556b2809fc 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -16,6 +16,9 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
#include "test/UnitTest/RoundingModeUtils.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
#include "mpfr_inc.h"
@@ -69,6 +72,10 @@ template <> struct ExtraPrecision<bfloat16> {
static constexpr unsigned int VALUE = 64;
};
+template <> struct ExtraPrecision<Float128> {
+ static constexpr unsigned int VALUE = VALUE = 512;
+}
+
// If the ulp tolerance is less than or equal to 0.5, we would check that the
// result is rounded correctly with respect to the rounding mode by using the
// same precision as the inputs.
@@ -116,7 +123,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType>,
+ || cpp::is_same_v<bfloat16, XType> || cpp:::is_same<Float128,XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
>From 0ac0422e71becee3bf9a8c468b2bf19a528c5052 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:23:07 +0530
Subject: [PATCH 38/51] shared_math_constexpr update
---
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_constexpr_test.cpp | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 07eaf80a6a0bb..b09e99ee9fde8 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -528,6 +528,7 @@ add_fp_unittest(
shared_math_constexpr_test.cpp
DEPENDS
libc.src.__support.math.asinbf16
+ libc.src.__support.FPUtil.float128
libc.src.__support.math.bf16subl
libc.src.__support.math.canonicalize
libc.src.__support.math.canonicalizebf16
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index d5d14dcc65f02..9e766977e5c81 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -10,6 +10,9 @@
#include "shared/math.h"
#include "test/UnitTest/Test.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;s
#ifdef LIBC_USE_CONSTEXPR
@@ -373,6 +376,11 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
#endif
+//emulated float128
+
+static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+
+
//===----------------------------------------------------------------------===//
// Float128 Tests
//===----------------------------------------------------------------------===//
@@ -384,7 +392,6 @@ static_assert(0 == [] {
float128 x = float128(0.0);
return LIBC_NAMESPACE::shared::canonicalizef128(&cx, &x);
}());
-static_assert(float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
static_assert(float128(1.0) ==
LIBC_NAMESPACE::shared::fabsf128(float128(-1.0)));
static_assert(float128(0.0) ==
>From 924e4735ada54637ba91688380baed636730b348 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:46:33 +0530
Subject: [PATCH 39/51] nits
---
libc/test/shared/shared_math_constexpr_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 9e766977e5c81..e5d22ffcfdd37 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -12,7 +12,7 @@
#include "test/UnitTest/Test.h"
#include "src/__support/FPUtil/float128.h"
-using LIBC_NAMESPACE::fputil::Float128;s
+using LIBC_NAMESPACE::fputil::Float128;
#ifdef LIBC_USE_CONSTEXPR
>From 7fe71b6f84594c62461d4dfb81efd50d94064d9d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:50:28 +0530
Subject: [PATCH 40/51] nits
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 56b556b2809fc..759f5474393fe 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -123,7 +123,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType> || cpp:::is_same<Float128,XType>,
+ || cpp::is_same_v<bfloat16, XType> || cpp::is_same<Float128,XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
>From b2b28d8288e01b3091e6ed4307d8c970ed382aa1 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:39:29 +0530
Subject: [PATCH 41/51] nits
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 759f5474393fe..a5ff74219b9e3 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -73,7 +73,7 @@ template <> struct ExtraPrecision<bfloat16> {
};
template <> struct ExtraPrecision<Float128> {
- static constexpr unsigned int VALUE = VALUE = 512;
+ static constexpr unsigned int VALUE = 512;
}
// If the ulp tolerance is less than or equal to 0.5, we would check that the
>From 9ff23aeb5206bb9260ea2d946900c960ad896618 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:45:17 +0530
Subject: [PATCH 42/51] nits
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index a5ff74219b9e3..3ebb08bdca87b 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -74,7 +74,7 @@ template <> struct ExtraPrecision<bfloat16> {
template <> struct ExtraPrecision<Float128> {
static constexpr unsigned int VALUE = 512;
-}
+};
// If the ulp tolerance is less than or equal to 0.5, we would check that the
// result is rounded correctly with respect to the rounding mode by using the
>From 0755815f76cc0115ed6dce1e27655b12001deb9a Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:50:06 +0530
Subject: [PATCH 43/51] nit
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 3ebb08bdca87b..a8dcdead70816 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -123,7 +123,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType> || cpp::is_same<Float128,XType>,
+ || cpp::is_same_v<bfloat16, XType> || cpp::is_same_v<Float128,XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
>From 7ce3d87588fa8f5ec8f52723b5df09d3aad9f20e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 14:21:38 +0530
Subject: [PATCH 44/51] nit
---
libc/utils/MPFRWrapper/MPFRUtils.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 356764302bda8..68d38f8650add 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -15,6 +15,9 @@
#include "src/__support/FPUtil/fpbits_str.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace testing {
@@ -286,6 +289,12 @@ template void explain_unary_operation_single_output_error(Operation op,
bfloat16, bfloat16,
double, RoundingMode);
+// Emulated Float128 is always available regardless of native float128 support.
+template void
+explain_unary_operation_single_output_error(Operation op, fputil::Float128,
+ fputil::Float128, double,
+ RoundingMode);
+
template <typename T>
void explain_unary_operation_two_outputs_error(
Operation op, T input, const BinaryOutput<T> &libc_result,
@@ -578,6 +587,10 @@ template bool compare_unary_operation_single_output(Operation, float128,
template bool compare_unary_operation_single_output(Operation, bfloat16,
bfloat16, double,
RoundingMode);
+// Emulated Float128
+template bool compare_unary_operation_single_output(Operation, fputil::Float128,
+ fputil::Float128, double,
+ RoundingMode);
template <typename T>
bool compare_unary_operation_two_outputs(Operation op, T input,
>From c405ef8655b5525f7b9178e4082e10422436cbf2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 14:29:13 +0530
Subject: [PATCH 45/51] nit
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index a8dcdead70816..f50df1c2c9154 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -297,7 +297,7 @@ class MPFRNumber {
if (FPBits<T>(input).is_subnormal())
++inputExponent;
- if (thisAsT * input < 0 || thisExponent == inputExponent) {
+ if (thisAsT * input < T(0) || thisExponent == inputExponent) {
MPFRNumber inputMPFR(input);
mpfr_sub(inputMPFR.value, value, inputMPFR.value, MPFR_RNDN);
mpfr_abs(inputMPFR.value, inputMPFR.value, MPFR_RNDN);
>From 180163339d41400a70fbb93e37d82fb91665bd84 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 2 Jul 2026 20:44:29 +0530
Subject: [PATCH 46/51] test mpfr_get_float128
---
libc/utils/MPFRWrapper/CMakeLists.txt | 122 +++++++++++++-------------
libc/utils/MPFRWrapper/MPCommon.cpp | 2 +-
2 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index a1324e9af33c9..fe328062c2b1c 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,61 +1,61 @@
-if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
- add_library(libcMPCommon STATIC
- MPCommon.cpp
- MPCommon.h
- mpfr_inc.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
- add_dependencies(
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.string
- libc.src.__support.CPP.string_view
- libc.src.__support.CPP.type_traits
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.float128
- libc.src.__support.FPUtil.cast
- libc.src.__support.FPUtil.fp_bits
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
-
-if(LIBC_TESTS_CAN_USE_MPFR)
- add_library(libcMPFRWrapper STATIC
- MPFRUtils.cpp
- MPFRUtils.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
- add_dependencies(
- libcMPFRWrapper
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.array
- libc.src.__support.CPP.stringstream
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.float128
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.fpbits_str
- LibcTest.unit
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
+if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
+ add_library(libcMPCommon STATIC
+ MPCommon.cpp
+ MPCommon.h
+ mpfr_inc.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
+ add_dependencies(
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.string
+ libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.fp_bits
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
+
+if(LIBC_TESTS_CAN_USE_MPFR)
+ add_library(libcMPFRWrapper STATIC
+ MPFRUtils.cpp
+ MPFRUtils.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
+ add_dependencies(
+ libcMPFRWrapper
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.array
+ libc.src.__support.CPP.stringstream
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.fpbits_str
+ LibcTest.unit
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index a636b091a15f8..f4492b0bf23ad 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -647,7 +647,7 @@ template <> bfloat16 MPFRNumber::as<bfloat16>() const {
}
template <> Float128 MPFRNumber::as<Float128>() const {
- return fputil::cast<Float128>(mpfr_get_flt(value, mpfr_rounding));
+ return fputil::cast<Float128>(mpfr_get_float128(value, mpfr_rounding));
}
} // namespace mpfr
>From 5ebf1cb2766371668e22196583e2afb70e5c2e33 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 2 Jul 2026 21:10:58 +0530
Subject: [PATCH 47/51] non-native mpfr_get_float128
---
libc/utils/MPFRWrapper/MPCommon.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index f50df1c2c9154..d055a1487b1eb 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -27,6 +27,11 @@ extern "C" {
int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
}
+#else
+extern "C"{
+int mpfr_set_float128(mpfr_ptr, Float128, mpfr_rnd_t);
+Float128 mpfr_get_float128(mpfr_srcptr,mpfr_rnd_t);
+}
#endif
namespace LIBC_NAMESPACE_DECL {
>From e70837f4488fd72af2d61615eef3b401abf86813 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 12:57:55 +0530
Subject: [PATCH 48/51] add template for Float128 separately
---
libc/utils/MPFRWrapper/MPCommon.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index d055a1487b1eb..d0f9388777fe0 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -128,7 +128,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType> || cpp::is_same_v<Float128,XType>,
+ || cpp::is_same_v<bfloat16, XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
@@ -174,6 +174,17 @@ class MPFRNumber {
}
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+ template <typename XType,
+ cpp::enable_if_t<cpp::is_same_v<Float128, XType>, int> = 0>
+ explicit MPFRNumber(XType x,
+ unsigned int precision = ExtraPrecision<XType>::VALUE,
+ RoundingMode rounding = RoundingMode::Nearest)
+ : mpfr_precision(precision),
+ mpfr_rounding(get_mpfr_rounding_mode(rounding)) {
+ mpfr_init2(value, mpfr_precision);
+ mpfr_set_float128(value, x, mpfr_rounding);
+ }
+
template <typename XType,
cpp::enable_if_t<cpp::is_integral_v<XType>, int> = 0>
explicit MPFRNumber(XType x,
>From b728e6d5d8291797083c5c23d5f29681dc28b1f0 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:00:30 +0530
Subject: [PATCH 49/51] formatting
---
libc/shared/math/ceilf128.h | 2 +-
libc/src/__support/math/ceilf128.h | 2 +-
libc/src/math/ceilf128.h | 2 +-
libc/src/math/generic/ceilf128.cpp | 2 +-
libc/test/shared/shared_math_test.cpp | 4 ++--
libc/test/src/math/ceilf128_test.cpp | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/shared/math/ceilf128.h b/libc/shared/math/ceilf128.h
index 25611636e2233..d7fe00fe86a3e 100644
--- a/libc/shared/math/ceilf128.h
+++ b/libc/shared/math/ceilf128.h
@@ -10,8 +10,8 @@
#define LLVM_LIBC_SHARED_MATH_CEILF128_H
#include "shared/libc_common.h"
-#include "src/__support/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/__support/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index f12fc6a11a07c..31b3debb890da 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -10,8 +10,8 @@
#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/macros/config.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/__support/macros/config.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/src/math/ceilf128.h b/libc/src/math/ceilf128.h
index 40de768feb299..32b69433767b5 100644
--- a/libc/src/math/ceilf128.h
+++ b/libc/src/math/ceilf128.h
@@ -9,9 +9,9 @@
#ifndef LLVM_LIBC_SRC_MATH_CEILF128_H
#define LLVM_LIBC_SRC_MATH_CEILF128_H
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index e359ef9cb18b7..acb5ed3b8b8ab 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceilf128.h"
-#include "src/__support/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/__support/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 165591594f45e..c71e44f71b23a 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -575,13 +575,13 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
-// Emulated float128
+// Emulated float128
// TODO: style
#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
-TEST(LlvmLibcSharedMathTest, AllEmuFloat128){
+TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
}
diff --git a/libc/test/src/math/ceilf128_test.cpp b/libc/test/src/math/ceilf128_test.cpp
index e01221f4ac6cd..accb766e1526d 100644
--- a/libc/test/src/math/ceilf128_test.cpp
+++ b/libc/test/src/math/ceilf128_test.cpp
@@ -8,8 +8,8 @@
#include "CeilTest.h"
-#include "src/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
>From 07b999aae22648855277886c6fa9184ee3477e17 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:36:00 +0530
Subject: [PATCH 50/51] chore: format
---
libc/test/shared/shared_math_constexpr_test.cpp | 5 ++---
libc/test/src/math/smoke/ceilf128_test.cpp | 2 +-
libc/utils/MPFRWrapper/MPCommon.cpp | 2 +-
libc/utils/MPFRWrapper/MPCommon.h | 8 ++++----
libc/utils/MPFRWrapper/MPFRUtils.cpp | 10 +++++-----
5 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index e5d22ffcfdd37..ed44fa4aa0be9 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -9,8 +9,8 @@
#define LIBC_ENABLE_CONSTEXPR 1
#include "shared/math.h"
-#include "test/UnitTest/Test.h"
#include "src/__support/FPUtil/float128.h"
+#include "test/UnitTest/Test.h"
using LIBC_NAMESPACE::fputil::Float128;
@@ -376,11 +376,10 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
#endif
-//emulated float128
+// emulated float128
static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
-
//===----------------------------------------------------------------------===//
// Float128 Tests
//===----------------------------------------------------------------------===//
diff --git a/libc/test/src/math/smoke/ceilf128_test.cpp b/libc/test/src/math/smoke/ceilf128_test.cpp
index e01221f4ac6cd..accb766e1526d 100644
--- a/libc/test/src/math/smoke/ceilf128_test.cpp
+++ b/libc/test/src/math/smoke/ceilf128_test.cpp
@@ -8,8 +8,8 @@
#include "CeilTest.h"
-#include "src/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index f4492b0bf23ad..a88b3fc94394f 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -11,9 +11,9 @@
#include "src/__support/CPP/string_view.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index d0f9388777fe0..a49b274d3e28d 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -13,10 +13,10 @@
#include "src/__support/CPP/string.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
#include "test/UnitTest/RoundingModeUtils.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
@@ -27,10 +27,10 @@ extern "C" {
int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
}
-#else
-extern "C"{
+#else
+extern "C" {
int mpfr_set_float128(mpfr_ptr, Float128, mpfr_rnd_t);
-Float128 mpfr_get_float128(mpfr_srcptr,mpfr_rnd_t);
+Float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
}
#endif
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 68d38f8650add..2a8d2d099890c 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -12,10 +12,10 @@
#include "src/__support/CPP/array.h"
#include "src/__support/CPP/stringstream.h"
#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/FPUtil/fpbits_str.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
@@ -290,10 +290,10 @@ template void explain_unary_operation_single_output_error(Operation op,
double, RoundingMode);
// Emulated Float128 is always available regardless of native float128 support.
-template void
-explain_unary_operation_single_output_error(Operation op, fputil::Float128,
- fputil::Float128, double,
- RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+ fputil::Float128,
+ fputil::Float128,
+ double, RoundingMode);
template <typename T>
void explain_unary_operation_two_outputs_error(
>From 3127d39b4bc380867a1c0d2f341d8476ebfe1acf Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 6 Jul 2026 16:18:57 +0530
Subject: [PATCH 51/51] guard for LD
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index a49b274d3e28d..7ba8ecf7d239d 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -22,7 +22,7 @@ using LIBC_NAMESPACE::fputil::Float128;
#include "mpfr_inc.h"
-#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+#ifdef LIBC_TYPES_HAS_FLOAT128
extern "C" {
int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
More information about the libc-commits
mailing list