[libc-commits] [libc] [llvm] [libc][math] Refactor fdiv family to header-only (PR #182192)

via libc-commits libc-commits at lists.llvm.org
Sat Apr 25 12:16:23 PDT 2026


https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/182192

>From 4110326595e343b0dd6433d437570ea1849a401e Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 19 Feb 2026 02:10:54 +0200
Subject: [PATCH 1/4] [libc][math] Refactor fdiv family to header-only

Refactored functions:
  - fdiv
  - fdivf128
  - fdivl
---
 libc/shared/math.h                            |  3 ++
 libc/shared/math/fdiv.h                       | 22 +++++++++
 libc/shared/math/fdivf128.h                   | 28 ++++++++++++
 libc/shared/math/fdivl.h                      | 22 +++++++++
 libc/src/__support/math/CMakeLists.txt        | 28 ++++++++++++
 libc/src/__support/math/fdiv.h                | 25 +++++++++++
 libc/src/__support/math/fdivf128.h            | 31 +++++++++++++
 libc/src/__support/math/fdivl.h               | 25 +++++++++++
 libc/src/math/generic/CMakeLists.txt          |  7 ++-
 libc/src/math/generic/fdiv.cpp                |  6 +--
 libc/src/math/generic/fdivf128.cpp            |  6 +--
 libc/src/math/generic/fdivl.cpp               |  6 +--
 libc/test/shared/CMakeLists.txt               |  3 ++
 libc/test/shared/shared_math_test.cpp         |  4 ++
 .../llvm-project-overlay/libc/BUILD.bazel     | 45 ++++++++++++++++++-
 15 files changed, 243 insertions(+), 18 deletions(-)
 create mode 100644 libc/shared/math/fdiv.h
 create mode 100644 libc/shared/math/fdivf128.h
 create mode 100644 libc/shared/math/fdivl.h
 create mode 100644 libc/src/__support/math/fdiv.h
 create mode 100644 libc/src/__support/math/fdivf128.h
 create mode 100644 libc/src/__support/math/fdivl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 275b89db3179a..d91e2c7b5c3e8 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -136,6 +136,9 @@
 #include "math/fdimf128.h"
 #include "math/fdimf16.h"
 #include "math/fdiml.h"
+#include "math/fdiv.h"
+#include "math/fdivf128.h"
+#include "math/fdivl.h"
 #include "math/ffma.h"
 #include "math/ffmaf128.h"
 #include "math/ffmal.h"
diff --git a/libc/shared/math/fdiv.h b/libc/shared/math/fdiv.h
new file mode 100644
index 0000000000000..b30535e88c43c
--- /dev/null
+++ b/libc/shared/math/fdiv.h
@@ -0,0 +1,22 @@
+//===-- Shared fdiv function ------------------------------------*- 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_SHARED_MATH_FDIV_H
+#define LLVM_LIBC_SHARED_MATH_FDIV_H
+
+#include "src/__support/math/fdiv.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fdiv;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FDIV_H
diff --git a/libc/shared/math/fdivf128.h b/libc/shared/math/fdivf128.h
new file mode 100644
index 0000000000000..07e44077da7b9
--- /dev/null
+++ b/libc/shared/math/fdivf128.h
@@ -0,0 +1,28 @@
+//===-- Shared fdivf128 function --------------------------------*- 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_SHARED_MATH_FDIVF128_H
+#define LLVM_LIBC_SHARED_MATH_FDIVF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/fdivf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fdivf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FDIVF128_H
diff --git a/libc/shared/math/fdivl.h b/libc/shared/math/fdivl.h
new file mode 100644
index 0000000000000..edc00132da43f
--- /dev/null
+++ b/libc/shared/math/fdivl.h
@@ -0,0 +1,22 @@
+//===-- Shared fdivl function -----------------------------------*- 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_SHARED_MATH_FDIVL_H
+#define LLVM_LIBC_SHARED_MATH_FDIVL_H
+
+#include "src/__support/math/fdivl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fdivl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FDIVL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 987ecab8c57ef..71ccb3e278473 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1361,6 +1361,34 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  fdiv
+  HDRS
+    fdiv.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fdivf128
+  HDRS
+    fdivf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fdivl
+  HDRS
+    fdivl.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   ffmaf128
   HDRS
diff --git a/libc/src/__support/math/fdiv.h b/libc/src/__support/math/fdiv.h
new file mode 100644
index 0000000000000..3993b04e1ecc8
--- /dev/null
+++ b/libc/src/__support/math/fdiv.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fdiv --------------------------*- 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_MATH_FDIV_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FDIV_H
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float fdiv(double x, double y) {
+  return fputil::generic::div<float>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FDIV_H
diff --git a/libc/src/__support/math/fdivf128.h b/libc/src/__support/math/fdivf128.h
new file mode 100644
index 0000000000000..002b931f97c52
--- /dev/null
+++ b/libc/src/__support/math/fdivf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fdivf128 ----------------------*- 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_MATH_FDIVF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FDIVF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float fdivf128(float128 x, float128 y) {
+  return fputil::generic::div<float>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FDIVF128_H
diff --git a/libc/src/__support/math/fdivl.h b/libc/src/__support/math/fdivl.h
new file mode 100644
index 0000000000000..36b4c2a719d45
--- /dev/null
+++ b/libc/src/__support/math/fdivl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fdivl -------------------------*- 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_MATH_FDIVL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FDIVL_H
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float fdivl(long double x, long double y) {
+  return fputil::generic::div<float>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FDIVL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 5d265b89391e6..8515bcbdf3286 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3149,7 +3149,7 @@ add_entrypoint_object(
   HDRS
     ../fdiv.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.fdiv
 )
 
 add_entrypoint_object(
@@ -3159,7 +3159,7 @@ add_entrypoint_object(
   HDRS
     ../fdivl.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.fdivl
 )
 
 add_entrypoint_object(
@@ -3169,8 +3169,7 @@ add_entrypoint_object(
   HDRS
     ../fdivf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.fdivf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/fdiv.cpp b/libc/src/math/generic/fdiv.cpp
index 1d97fade22a37..da90852604c5f 100644
--- a/libc/src/math/generic/fdiv.cpp
+++ b/libc/src/math/generic/fdiv.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fdiv.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fdiv.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fdiv, (double x, double y)) {
-  return fputil::generic::div<float>(x, y);
+  return math::fdiv(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fdivf128.cpp b/libc/src/math/generic/fdivf128.cpp
index 192f13f5de10e..1ab0eb3003062 100644
--- a/libc/src/math/generic/fdivf128.cpp
+++ b/libc/src/math/generic/fdivf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fdivf128.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fdivf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fdivf128, (float128 x, float128 y)) {
-  return fputil::generic::div<float>(x, y);
+  return math::fdivf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fdivl.cpp b/libc/src/math/generic/fdivl.cpp
index dcd5debc2acd9..ac29aed5e04a0 100644
--- a/libc/src/math/generic/fdivl.cpp
+++ b/libc/src/math/generic/fdivl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fdivl.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fdivl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fdivl, (long double x, long double y)) {
-  return fputil::generic::div<float>(x, y);
+  return math::fdivl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 9c4b7edb377e2..b5e2cceae053d 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -133,6 +133,9 @@ add_fp_unittest(
     libc.src.__support.math.fdimf128
     libc.src.__support.math.fdimf16
     libc.src.__support.math.fdiml
+    libc.src.__support.math.fdiv
+    libc.src.__support.math.fdivf128
+    libc.src.__support.math.fdivl
     libc.src.__support.math.ffma
     libc.src.__support.math.ffmaf128
     libc.src.__support.math.ffmal
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 4c58c834960ed..cb3953684b5e0 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -257,6 +257,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::ceil(0.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fadd(0.0, 0.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fdim(0.0, 0.0));
+  EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::shared::fdiv(1.0, 1.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::floor(0.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmax(0.0, 0.0));
   double getpayload_x = 0.0;
@@ -317,6 +318,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::daddl(0.0L, 0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::faddl(0.0L, 0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::fdiml(0.0L, 0.0L));
+  EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::shared::fdivl(1.0L, 1.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::floorl(0.0L));
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::fmaxl(0.0L, 0.0L));
   long double getpayloadl_x = 0.0L;
@@ -401,6 +403,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::floorf128(float128(0.0)));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::fdimf128(float128(0.0), float128(0.0)));
+  EXPECT_FP_EQ(1.0f,
+               LIBC_NAMESPACE::shared::fdivf128(float128(1.0), float128(1.0)));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::fmaxf128(float128(0.0), float128(0.0)));
 
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index d97d65e4ee43a..d75c49d2e8a4e 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4285,6 +4285,34 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_fdiv",
+    hdrs = ["src/__support/math/fdiv.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fdivf128",
+    hdrs = ["src/__support/math/fdivf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fdivl",
+    hdrs = ["src/__support/math/fdivl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_f16mul",
     hdrs = ["src/__support/math/f16mul.h"],
@@ -7422,12 +7450,25 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "fdiv")
+libc_math_function(
+    name = "fdiv",
+    additional_deps = [
+        ":__support_math_fdiv",
+    ],
+)
 
-libc_math_function(name = "fdivl")
+libc_math_function(
+    name = "fdivl",
+    additional_deps = [
+        ":__support_math_fdivl",
+    ],
+)
 
 libc_math_function(
     name = "fdivf128",
+    additional_deps = [
+        ":__support_math_fdivf128",
+    ],
 )
 
 libc_math_function(

>From 32a95120033edd6575f1a88bc13074d2b74dde7c Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Sat, 14 Mar 2026 02:25:14 +0200
Subject: [PATCH 2/4] missed libc_common

---
 libc/shared/math/fdiv.h     | 1 +
 libc/shared/math/fdivf128.h | 1 +
 libc/shared/math/fdivl.h    | 1 +
 3 files changed, 3 insertions(+)

diff --git a/libc/shared/math/fdiv.h b/libc/shared/math/fdiv.h
index b30535e88c43c..5a4455f6f2951 100644
--- a/libc/shared/math/fdiv.h
+++ b/libc/shared/math/fdiv.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_SHARED_MATH_FDIV_H
 #define LLVM_LIBC_SHARED_MATH_FDIV_H
 
+#include "shared/libc_common.h"
 #include "src/__support/math/fdiv.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/shared/math/fdivf128.h b/libc/shared/math/fdivf128.h
index 07e44077da7b9..cb96aebcd903b 100644
--- a/libc/shared/math/fdivf128.h
+++ b/libc/shared/math/fdivf128.h
@@ -13,6 +13,7 @@
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
 
+#include "shared/libc_common.h"
 #include "src/__support/math/fdivf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/shared/math/fdivl.h b/libc/shared/math/fdivl.h
index edc00132da43f..cb832923b823b 100644
--- a/libc/shared/math/fdivl.h
+++ b/libc/shared/math/fdivl.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_SHARED_MATH_FDIVL_H
 #define LLVM_LIBC_SHARED_MATH_FDIVL_H
 
+#include "shared/libc_common.h"
 #include "src/__support/math/fdivl.h"
 
 namespace LIBC_NAMESPACE_DECL {

>From 1d2a975eeba73df3f2daa429416b594913e631bc Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 22 Apr 2026 22:46:08 +0200
Subject: [PATCH 3/4] make constexpr

---
 libc/src/__support/math/fdiv.h                  | 2 +-
 libc/src/__support/math/fdivf128.h              | 2 +-
 libc/src/__support/math/fdivl.h                 | 2 +-
 libc/test/shared/CMakeLists.txt                 | 3 +++
 libc/test/shared/shared_math_constexpr_test.cpp | 3 +++
 5 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libc/src/__support/math/fdiv.h b/libc/src/__support/math/fdiv.h
index 3993b04e1ecc8..be21838be8265 100644
--- a/libc/src/__support/math/fdiv.h
+++ b/libc/src/__support/math/fdiv.h
@@ -15,7 +15,7 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE float fdiv(double x, double y) {
+LIBC_INLINE constexpr float fdiv(double x, double y) {
   return fputil::generic::div<float>(x, y);
 }
 
diff --git a/libc/src/__support/math/fdivf128.h b/libc/src/__support/math/fdivf128.h
index 002b931f97c52..2ab5ea31072c3 100644
--- a/libc/src/__support/math/fdivf128.h
+++ b/libc/src/__support/math/fdivf128.h
@@ -19,7 +19,7 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE float fdivf128(float128 x, float128 y) {
+LIBC_INLINE constexpr float fdivf128(float128 x, float128 y) {
   return fputil::generic::div<float>(x, y);
 }
 
diff --git a/libc/src/__support/math/fdivl.h b/libc/src/__support/math/fdivl.h
index 36b4c2a719d45..a75f4fd82cbfe 100644
--- a/libc/src/__support/math/fdivl.h
+++ b/libc/src/__support/math/fdivl.h
@@ -15,7 +15,7 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE float fdivl(long double x, long double y) {
+LIBC_INLINE constexpr float fdivl(long double x, long double y) {
   return fputil::generic::div<float>(x, y);
 }
 
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index b5e2cceae053d..9c10273a48809 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -280,6 +280,9 @@ add_fp_unittest(
     libc.src.__support.math.ceilf128
     libc.src.__support.math.ceilf16
     libc.src.__support.math.ceill
+    libc.src.__support.math.fdiv
+    libc.src.__support.math.fdivf128
+    libc.src.__support.math.fdivl
     libc.src.__support.math.log
 )
 
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 53d416de30694..6db45eb0e55cd 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -16,6 +16,7 @@
 //===----------------------------------------------------------------------===//
 
 static_assert(0.0 == LIBC_NAMESPACE::shared::ceil(0.0));
+static_assert(0.0f == LIBC_NAMESPACE::shared::fdiv(0.0, 1.0));
 static_assert(0.0 == LIBC_NAMESPACE::shared::log(1.0));
 
 //===----------------------------------------------------------------------===//
@@ -42,6 +43,7 @@ static_assert(0.0f16 == LIBC_NAMESPACE::shared::ceilf16(0.0f16));
 #if 0 // Temporarily disable long double tests
 
 static_assert(0.0L == LIBC_NAMESPACE::shared::ceill(0.0L));
+static_assert(0.0f == LIBC_NAMESPACE::shared::fdivl(0.0L, 1.0L));
 
 #endif
 
@@ -52,6 +54,7 @@ static_assert(0.0L == LIBC_NAMESPACE::shared::ceill(0.0L));
 #ifdef LIBC_TYPES_HAS_FLOAT128
 
 static_assert(float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
+static_assert(0.0f == LIBC_NAMESPACE::shared::fdivf128(float128(0.0), float128(1.0)));
 
 #endif // LIBC_TYPES_HAS_FLOAT128
 

>From 0e1d63faf94a930cb5fc509ec06369961745ca82 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Sat, 25 Apr 2026 22:15:07 +0300
Subject: [PATCH 4/4] fix format

---
 libc/test/shared/shared_math_constexpr_test.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 695fcad3a777a..18519fc8608ee 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -77,7 +77,9 @@ static_assert(0.0 ==
               LIBC_NAMESPACE::shared::ddivf128(float128(0.0), float128(1.0)));
 static_assert(0.0 ==
               LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(1.0)));
-static_assert(0.0f == 
+static_assert(0.0f ==
+              LIBC_NAMESPACE::shared::fdivf128(float128(0.0), float128(1.0)));
+static_assert(0.0f ==
               LIBC_NAMESPACE::shared::fdivf128(float128(0.0), float128(1.0)));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::floorf128(float128(0.0)));



More information about the libc-commits mailing list