[libc-commits] [libc] [libc] Make ceilf128 use the emulated float128 type (PR #207735)

via libc-commits libc-commits at lists.llvm.org
Thu Aug 6 07:51:59 PDT 2026


https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/207735

>From e84053381a392b1f6f2ae61229df892c9c8105e6 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:00:33 +0530
Subject: [PATCH 01/26] 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 e3c54509103ed726bd9acd90c27991ecd6ff417d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:15:56 +0530
Subject: [PATCH 02/26] 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 9da54744b5307..76c2d8c8fe7b7 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -576,6 +576,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) {
@@ -621,7 +631,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 727c657c2ef3ef57242cafc976ab6a42693c56e2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:23:17 +0530
Subject: [PATCH 03/26] 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 2c79c5432f59f..334dddd9154e0 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 299526dd0dd783605109fe0303dabb452a3a27de Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:35:44 +0530
Subject: [PATCH 04/26] 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 9f4624682eafe..93d226b807a67 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 d5661f6f55e91..83c6d7bf55bd7 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 6fbe43501e017..0167cc3fc1ad3 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -435,6 +435,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 d3f93d31a39b0..d083c8a36e8e8 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -618,6 +618,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 8161c414390ea808fdfc7dd8a0bca881612d2fc7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:41:00 +0530
Subject: [PATCH 05/26] 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 ac5ae7f935ecbb8caa9ca0766d2a4f55cc226441 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:17:21 +0530
Subject: [PATCH 06/26] 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 2422bcf45222f..8546aef2a2ff5 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 {
@@ -650,6 +653,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 38fd15fcc956c..518144fd9160a 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 617cfa10cf65dde9589bcbca887483f9262e8f40 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:23:07 +0530
Subject: [PATCH 07/26] 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 334dddd9154e0..7dc59d9fbe8fd 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -529,6 +529,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 8ca444672edcbe1acf9a5cfc2ab143760cb97a5f Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:46:33 +0530
Subject: [PATCH 08/26] 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 707237aeaf84bf904ee1ae93bef47ba48000f116 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:50:28 +0530
Subject: [PATCH 09/26] 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 518144fd9160a..6339283fe5e05 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 ce6fd82a7538ada3125e66d8fbd6d0337040ad35 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:39:29 +0530
Subject: [PATCH 10/26] 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 6339283fe5e05..43acdfd28e9ae 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 bd6ee4add0b1b714f23ca1dc4fb8bfb4764f2f73 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:45:17 +0530
Subject: [PATCH 11/26] 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 43acdfd28e9ae..a5c2af909445f 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 f798419af27f1b16fb831695b3fcb948a8f489c2 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:50:06 +0530
Subject: [PATCH 12/26] 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 a5c2af909445f..60d89edcf4287 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 1c0afd3ed4ad354da20fab69382595c08485c447 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 14:21:38 +0530
Subject: [PATCH 13/26] 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 d585baa2e0d2c..e3f612dc4c008 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 {
@@ -288,6 +291,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,
@@ -580,6 +589,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 7bbc51b668e54072f0cd6f67d63e5bc14cdb5b57 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 14:29:13 +0530
Subject: [PATCH 14/26] 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 60d89edcf4287..ee5a69f0353d1 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -298,7 +298,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 56e75f6134e42bab01717f83e2866f104d057253 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 2 Jul 2026 20:44:29 +0530
Subject: [PATCH 15/26] 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 8546aef2a2ff5..fb9573ca424f8 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -654,7 +654,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 bf307965ca3fb56765684759adb0422c8aedfaaa Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 2 Jul 2026 21:10:58 +0530
Subject: [PATCH 16/26] 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 ee5a69f0353d1..72444375c262d 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 cdf523ee40d3cb33568a857dfec4e521cae2b9bf Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 12:57:55 +0530
Subject: [PATCH 17/26] 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 72444375c262d..981f6ba23df93 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 802cf65ab2eff4992362e111f00ff5e96212fb9e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:00:30 +0530
Subject: [PATCH 18/26] 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 76c2d8c8fe7b7..3d52f190f55c1 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -576,13 +576,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 9fa8cd4267a764c75ebab3f6f6ab8597d9d76bfa Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:36:00 +0530
Subject: [PATCH 19/26] 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 fb9573ca424f8..b3d0b3ca77122 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 981f6ba23df93..3d364cdcd8dee 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 e3f612dc4c008..14a6f908f6062 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;
 
@@ -292,10 +292,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 9252852cfb77033a7ddb45ab4887875af9c5da6d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 6 Jul 2026 16:18:57 +0530
Subject: [PATCH 20/26] 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 3d364cdcd8dee..96e1d35b7777a 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);

>From 73eb26a4ff061298f8d1f8e888ff981cd938c2f3 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 30 Jul 2026 01:37:18 +0530
Subject: [PATCH 21/26] test

---
 libc/src/__support/math/CMakeLists.txt |  1 +
 libc/src/__support/math/ceilf128.h     | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 93d226b807a67..902fad2a08eb5 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -816,6 +816,7 @@ add_header_library(
     libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.nearest_integer_operations
     libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
 )
 
 add_header_library(
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 31b3debb890da..c89198780696a 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -12,13 +12,22 @@
 #include "src/__support/FPUtil/NearestIntegerOperations.h"
 #include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
 
 using LIBC_NAMESPACE::fputil::Float128;
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr Float128 ceilf128(Float128 x) { return fputil::ceil(x); }
+#ifdef LIBC_TYPES_HAS_FLOAT128
+LIBC_INLINE constexpr float128 ceilf128(float128 x) {
+  return static_cast<float128>(fputil::ceil(fputil::Float128(x)));
+}
+#else
+LIBC_INLINE constexpr fputil::Float128 ceilf128(fputil::Float128 x) {
+  return fputil::ceil(x);
+}
+#endif // LIBC_TYPES_HAS_FLOAT128
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL

>From 3483e05bc627774856e2c874cf86e1d4e3c92f88 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 30 Jul 2026 20:25:15 +0530
Subject: [PATCH 22/26] test

---
 libc/src/__support/math/ceilf128.h   | 4 ++--
 libc/src/math/generic/CMakeLists.txt | 1 +
 libc/src/math/generic/ceilf128.cpp   | 7 +++++++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index c89198780696a..32050b9c80c99 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -21,10 +21,10 @@ namespace math {
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
 LIBC_INLINE constexpr float128 ceilf128(float128 x) {
-  return static_cast<float128>(fputil::ceil(fputil::Float128(x)));
+  return static_cast<float128>(fputil::ceil(Float128(x)));
 }
 #else
-LIBC_INLINE constexpr fputil::Float128 ceilf128(fputil::Float128 x) {
+LIBC_INLINE constexpr Float128 ceilf128(Float128 x) {
   return fputil::ceil(x);
 }
 #endif // LIBC_TYPES_HAS_FLOAT128
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 83c6d7bf55bd7..924c9b83f5e85 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -163,6 +163,7 @@ add_entrypoint_object(
   DEPENDS
     libc.src.__support.math.ceilf128
     libc.src.__support.FPUtil.float128
+    libc.src.__support.macros.properties.types
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index acb5ed3b8b8ab..685518ed49d32 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -9,13 +9,20 @@
 #include "src/math/ceilf128.h"
 #include "src/__support/FPUtil/float128.h"
 #include "src/__support/math/ceilf128.h"
+#include "src/__support/macros/properties/types.h"
 
 using LIBC_NAMESPACE::fputil::Float128;
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifdef LIBC_TYPES_HAS_FLOAT128
+LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
+  return  static_cast<float128>(math::ceilf128(Float128(x)));
+}
+#else
 LLVM_LIBC_FUNCTION(Float128, ceilf128, (Float128 x)) {
   return math::ceilf128(x);
 }
+#endif // LIBC_TYPES_HAS_FLOAT128
 
 } // namespace LIBC_NAMESPACE_DECL

>From 45cacf81fbceb41ab28422824c0dd3835c1026dc Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 1 Aug 2026 00:02:47 +0530
Subject: [PATCH 23/26] structured and applied suggestions

---
 libc/src/__support/math/CMakeLists.txt          |  1 -
 libc/src/__support/math/ceilf128.h              | 13 +------------
 libc/src/math/generic/CMakeLists.txt            |  2 --
 libc/src/math/generic/ceilf128.cpp              | 12 +++---------
 libc/test/shared/CMakeLists.txt                 |  2 +-
 libc/test/shared/shared_math_constexpr_test.cpp |  6 ++++--
 libc/test/src/math/CMakeLists.txt               |  1 -
 libc/test/src/math/ceilf128_test.cpp            |  3 ---
 libc/test/src/math/smoke/CMakeLists.txt         |  1 -
 libc/test/src/math/smoke/ceilf128_test.cpp      |  3 ---
 libc/utils/MPFRWrapper/CMakeLists.txt           |  2 +-
 11 files changed, 10 insertions(+), 36 deletions(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 902fad2a08eb5..93d226b807a67 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -816,7 +816,6 @@ add_header_library(
     libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.nearest_integer_operations
     libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
 )
 
 add_header_library(
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 32050b9c80c99..cd6af62926c97 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -12,22 +12,11 @@
 #include "src/__support/FPUtil/NearestIntegerOperations.h"
 #include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h"
-
-using LIBC_NAMESPACE::fputil::Float128;
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-#ifdef LIBC_TYPES_HAS_FLOAT128
-LIBC_INLINE constexpr float128 ceilf128(float128 x) {
-  return static_cast<float128>(fputil::ceil(Float128(x)));
-}
-#else
-LIBC_INLINE constexpr Float128 ceilf128(Float128 x) {
-  return fputil::ceil(x);
-}
-#endif // LIBC_TYPES_HAS_FLOAT128
+LIBC_INLINE constexpr Float128 ceilf128(Float128 x) { return fputil::ceil(x); }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 924c9b83f5e85..d5661f6f55e91 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -162,8 +162,6 @@ add_entrypoint_object(
     ../ceilf128.h
   DEPENDS
     libc.src.__support.math.ceilf128
-    libc.src.__support.FPUtil.float128
-    libc.src.__support.macros.properties.types
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index 685518ed49d32..6320a791fe036 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -7,22 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/ceilf128.h"
-#include "src/__support/FPUtil/float128.h"
 #include "src/__support/math/ceilf128.h"
-#include "src/__support/macros/properties/types.h"
 
-using LIBC_NAMESPACE::fputil::Float128;
+#ifndef LIBC_TYPES_HAS_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_FLOAT128
 
 namespace LIBC_NAMESPACE_DECL {
 
-#ifdef LIBC_TYPES_HAS_FLOAT128
 LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
-  return  static_cast<float128>(math::ceilf128(Float128(x)));
-}
-#else
-LLVM_LIBC_FUNCTION(Float128, ceilf128, (Float128 x)) {
   return math::ceilf128(x);
 }
-#endif // LIBC_TYPES_HAS_FLOAT128
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 7dc59d9fbe8fd..d5293f228eafb 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -528,8 +528,8 @@ add_fp_unittest(
   SRCS
     shared_math_constexpr_test.cpp
   DEPENDS
-    libc.src.__support.math.asinbf16
     libc.src.__support.FPUtil.float128
+    libc.src.__support.math.asinbf16
     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 ed44fa4aa0be9..b6d0d53479312 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -376,12 +376,14 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
 
 #endif
 
-// emulated float128
+//===----------------------------------------------------------------------===//
+//                       Emulated Float128 Tests
+//===----------------------------------------------------------------------===//
 
 static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
 
 //===----------------------------------------------------------------------===//
-//                       Float128 Tests
+//                       Built-In Float128 Tests
 //===----------------------------------------------------------------------===//
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 0167cc3fc1ad3..6fbe43501e017 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -435,7 +435,6 @@ 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/ceilf128_test.cpp b/libc/test/src/math/ceilf128_test.cpp
index accb766e1526d..b60e64bc0c838 100644
--- a/libc/test/src/math/ceilf128_test.cpp
+++ b/libc/test/src/math/ceilf128_test.cpp
@@ -8,9 +8,6 @@
 
 #include "CeilTest.h"
 
-#include "src/__support/FPUtil/float128.h"
 #include "src/math/ceilf128.h"
 
-using LIBC_NAMESPACE::fputil::Float128;
-
 LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index d083c8a36e8e8..d3f93d31a39b0 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -618,7 +618,6 @@ 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 accb766e1526d..b60e64bc0c838 100644
--- a/libc/test/src/math/smoke/ceilf128_test.cpp
+++ b/libc/test/src/math/smoke/ceilf128_test.cpp
@@ -8,9 +8,6 @@
 
 #include "CeilTest.h"
 
-#include "src/__support/FPUtil/float128.h"
 #include "src/math/ceilf128.h"
 
-using LIBC_NAMESPACE::fputil::Float128;
-
 LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index fe328062c2b1c..0b725be062f49 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -15,8 +15,8 @@ if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
     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.float128
     libc.src.__support.FPUtil.fp_bits
   )
   if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})

>From b1883a8f470f7ddafd6b5322958ca4a820080e8f Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 1 Aug 2026 00:06:36 +0530
Subject: [PATCH 24/26] nit

---
 libc/src/__support/math/ceilf128.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index cd6af62926c97..31b3debb890da 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -13,6 +13,8 @@
 #include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 

>From 05f47fe449191518882dfa4210aae57448eb56bd Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 20:03:08 +0530
Subject: [PATCH 25/26] nits

---
 libc/src/math/ceilf128.h                   | 6 ++++--
 libc/src/math/generic/ceilf128.cpp         | 2 +-
 libc/test/src/math/smoke/ceilf128_test.cpp | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libc/src/math/ceilf128.h b/libc/src/math/ceilf128.h
index 32b69433767b5..6ad7dc7c8918d 100644
--- a/libc/src/math/ceilf128.h
+++ b/libc/src/math/ceilf128.h
@@ -13,11 +13,13 @@
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
-using LIBC_NAMESPACE::fputil::Float128;
+#ifndef LIBC_TYPES_HAS_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_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 6320a791fe036..7b5a9954d9b6a 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -16,7 +16,7 @@ using float128 = LIBC_NAMESPACE::fputil::Float128;
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
-  return math::ceilf128(x);
+  return fputil::cast<float128>(math::ceilf128(Float128(x)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/ceilf128_test.cpp b/libc/test/src/math/smoke/ceilf128_test.cpp
index b60e64bc0c838..f0da8258f79bc 100644
--- a/libc/test/src/math/smoke/ceilf128_test.cpp
+++ b/libc/test/src/math/smoke/ceilf128_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/math/ceilf128.h"
 
-LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
+LIST_CEIL_TESTS(float128, LIBC_NAMESPACE::ceilf128)

>From a33bbb82443ce04f881115942efc03d4e5b8d689 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 20:21:17 +0530
Subject: [PATCH 26/26] nit

---
 libc/test/src/math/ceilf128_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/math/ceilf128_test.cpp b/libc/test/src/math/ceilf128_test.cpp
index b60e64bc0c838..f0da8258f79bc 100644
--- a/libc/test/src/math/ceilf128_test.cpp
+++ b/libc/test/src/math/ceilf128_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/math/ceilf128.h"
 
-LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
+LIST_CEIL_TESTS(float128, LIBC_NAMESPACE::ceilf128)



More information about the libc-commits mailing list