[libc-commits] [libc] [llvm] [libc][math] Refactor fmod-modf family to header-only (PR #195406)

via libc-commits libc-commits at lists.llvm.org
Fri May 1 21:47:10 PDT 2026


https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/195406

>From dc283ffe5234ed2428b1d03a7c48594613c81fc7 Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Sat, 2 May 2026 06:21:23 +0300
Subject: [PATCH] [libc][math] Refactor fmod-modf family to header-only

Refactored functions:
  - fmod
  - fmodbf16
  - fmodf
  - fmodf128
  - fmodf16
  - fmodl
  - modf
  - modfbf16
  - modff
  - modff128
  - modff16
  - modfl
---
 libc/shared/math.h                            |  12 ++
 libc/shared/math/fmod.h                       |  23 +++
 libc/shared/math/fmodbf16.h                   |  23 +++
 libc/shared/math/fmodf.h                      |  23 +++
 libc/shared/math/fmodf128.h                   |  29 +++
 libc/shared/math/fmodf16.h                    |  29 +++
 libc/shared/math/fmodl.h                      |  23 +++
 libc/shared/math/modf.h                       |  23 +++
 libc/shared/math/modfbf16.h                   |  23 +++
 libc/shared/math/modff.h                      |  23 +++
 libc/shared/math/modff128.h                   |  29 +++
 libc/shared/math/modff16.h                    |  29 +++
 libc/shared/math/modfl.h                      |  23 +++
 .../__support/FPUtil/ManipulationFunctions.h  |   2 +-
 libc/src/__support/FPUtil/generic/FMod.h      |  10 +-
 libc/src/__support/math/CMakeLists.txt        | 113 ++++++++++++
 libc/src/__support/math/fmod.h                |  25 +++
 libc/src/__support/math/fmodbf16.h            |  26 +++
 libc/src/__support/math/fmodf.h               |  25 +++
 libc/src/__support/math/fmodf128.h            |  31 ++++
 libc/src/__support/math/fmodf16.h             |  31 ++++
 libc/src/__support/math/fmodl.h               |  25 +++
 libc/src/__support/math/modf.h                |  25 +++
 libc/src/__support/math/modfbf16.h            |  26 +++
 libc/src/__support/math/modff.h               |  25 +++
 libc/src/__support/math/modff128.h            |  31 ++++
 libc/src/__support/math/modff16.h             |  31 ++++
 libc/src/__support/math/modfl.h               |  25 +++
 libc/src/math/generic/CMakeLists.txt          |  36 ++--
 libc/src/math/generic/fmod.cpp                |   6 +-
 libc/src/math/generic/fmodbf16.cpp            |   7 +-
 libc/src/math/generic/fmodf.cpp               |   6 +-
 libc/src/math/generic/fmodf128.cpp            |   6 +-
 libc/src/math/generic/fmodf16.cpp             |   6 +-
 libc/src/math/generic/fmodl.cpp               |   6 +-
 libc/src/math/generic/modf.cpp                |   6 +-
 libc/src/math/generic/modfbf16.cpp            |   7 +-
 libc/src/math/generic/modff.cpp               |   6 +-
 libc/src/math/generic/modff128.cpp            |   6 +-
 libc/src/math/generic/modff16.cpp             |   6 +-
 libc/src/math/generic/modfl.cpp               |   6 +-
 libc/test/shared/CMakeLists.txt               |  24 +++
 .../shared/shared_math_constexpr_test.cpp     | 129 +++++++++-----
 libc/test/shared/shared_math_test.cpp         |  27 +++
 .../llvm-project-overlay/libc/BUILD.bazel     | 167 ++++++++++++++++--
 45 files changed, 1081 insertions(+), 139 deletions(-)
 create mode 100644 libc/shared/math/fmod.h
 create mode 100644 libc/shared/math/fmodbf16.h
 create mode 100644 libc/shared/math/fmodf.h
 create mode 100644 libc/shared/math/fmodf128.h
 create mode 100644 libc/shared/math/fmodf16.h
 create mode 100644 libc/shared/math/fmodl.h
 create mode 100644 libc/shared/math/modf.h
 create mode 100644 libc/shared/math/modfbf16.h
 create mode 100644 libc/shared/math/modff.h
 create mode 100644 libc/shared/math/modff128.h
 create mode 100644 libc/shared/math/modff16.h
 create mode 100644 libc/shared/math/modfl.h
 create mode 100644 libc/src/__support/math/fmod.h
 create mode 100644 libc/src/__support/math/fmodbf16.h
 create mode 100644 libc/src/__support/math/fmodf.h
 create mode 100644 libc/src/__support/math/fmodf128.h
 create mode 100644 libc/src/__support/math/fmodf16.h
 create mode 100644 libc/src/__support/math/fmodl.h
 create mode 100644 libc/src/__support/math/modf.h
 create mode 100644 libc/src/__support/math/modfbf16.h
 create mode 100644 libc/src/__support/math/modff.h
 create mode 100644 libc/src/__support/math/modff128.h
 create mode 100644 libc/src/__support/math/modff16.h
 create mode 100644 libc/src/__support/math/modfl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index c5e2371e7fe64..42826eaa98067 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -223,6 +223,12 @@
 #include "math/fminimumf16.h"
 #include "math/fminimuml.h"
 #include "math/fminl.h"
+#include "math/fmod.h"
+#include "math/fmodbf16.h"
+#include "math/fmodf.h"
+#include "math/fmodf128.h"
+#include "math/fmodf16.h"
+#include "math/fmodl.h"
 #include "math/frexpf.h"
 #include "math/frexpf128.h"
 #include "math/frexpf16.h"
@@ -274,6 +280,12 @@
 #include "math/logbl.h"
 #include "math/logf.h"
 #include "math/logf16.h"
+#include "math/modf.h"
+#include "math/modfbf16.h"
+#include "math/modff.h"
+#include "math/modff128.h"
+#include "math/modff16.h"
+#include "math/modfl.h"
 #include "math/nextafter.h"
 #include "math/nextafterbf16.h"
 #include "math/nextafterf.h"
diff --git a/libc/shared/math/fmod.h b/libc/shared/math/fmod.h
new file mode 100644
index 0000000000000..7c90e2392fe49
--- /dev/null
+++ b/libc/shared/math/fmod.h
@@ -0,0 +1,23 @@
+//===-- Shared fmod 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_FMOD_H
+#define LLVM_LIBC_SHARED_MATH_FMOD_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmod.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmod;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMOD_H
diff --git a/libc/shared/math/fmodbf16.h b/libc/shared/math/fmodbf16.h
new file mode 100644
index 0000000000000..71f1f2f7f4c19
--- /dev/null
+++ b/libc/shared/math/fmodbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fmodbf16 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_FMODBF16_H
+#define LLVM_LIBC_SHARED_MATH_FMODBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODBF16_H
diff --git a/libc/shared/math/fmodf.h b/libc/shared/math/fmodf.h
new file mode 100644
index 0000000000000..bec012c77a9a3
--- /dev/null
+++ b/libc/shared/math/fmodf.h
@@ -0,0 +1,23 @@
+//===-- Shared fmodf 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_FMODF_H
+#define LLVM_LIBC_SHARED_MATH_FMODF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODF_H
diff --git a/libc/shared/math/fmodf128.h b/libc/shared/math/fmodf128.h
new file mode 100644
index 0000000000000..9d1c48477d79e
--- /dev/null
+++ b/libc/shared/math/fmodf128.h
@@ -0,0 +1,29 @@
+//===-- Shared fmodf128 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_FMODF128_H
+#define LLVM_LIBC_SHARED_MATH_FMODF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODF128_H
diff --git a/libc/shared/math/fmodf16.h b/libc/shared/math/fmodf16.h
new file mode 100644
index 0000000000000..e2944fddb5a3d
--- /dev/null
+++ b/libc/shared/math/fmodf16.h
@@ -0,0 +1,29 @@
+//===-- Shared fmodf16 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_FMODF16_H
+#define LLVM_LIBC_SHARED_MATH_FMODF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODF16_H
diff --git a/libc/shared/math/fmodl.h b/libc/shared/math/fmodl.h
new file mode 100644
index 0000000000000..6b61bbf57a175
--- /dev/null
+++ b/libc/shared/math/fmodl.h
@@ -0,0 +1,23 @@
+//===-- Shared fmodl 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_FMODL_H
+#define LLVM_LIBC_SHARED_MATH_FMODL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODL_H
diff --git a/libc/shared/math/modf.h b/libc/shared/math/modf.h
new file mode 100644
index 0000000000000..3b16dac78ea3b
--- /dev/null
+++ b/libc/shared/math/modf.h
@@ -0,0 +1,23 @@
+//===-- Shared modf 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_MODF_H
+#define LLVM_LIBC_SHARED_MATH_MODF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODF_H
diff --git a/libc/shared/math/modfbf16.h b/libc/shared/math/modfbf16.h
new file mode 100644
index 0000000000000..3cecf890bb588
--- /dev/null
+++ b/libc/shared/math/modfbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared modfbf16 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_MODFBF16_H
+#define LLVM_LIBC_SHARED_MATH_MODFBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modfbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modfbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFBF16_H
diff --git a/libc/shared/math/modff.h b/libc/shared/math/modff.h
new file mode 100644
index 0000000000000..23752ba41daf6
--- /dev/null
+++ b/libc/shared/math/modff.h
@@ -0,0 +1,23 @@
+//===-- Shared modff 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_MODFF_H
+#define LLVM_LIBC_SHARED_MATH_MODFF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modff.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modff;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFF_H
diff --git a/libc/shared/math/modff128.h b/libc/shared/math/modff128.h
new file mode 100644
index 0000000000000..bbc6b8e4d09c0
--- /dev/null
+++ b/libc/shared/math/modff128.h
@@ -0,0 +1,29 @@
+//===-- Shared modff128 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_MODFF128_H
+#define LLVM_LIBC_SHARED_MATH_MODFF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modff128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modff128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFF128_H
diff --git a/libc/shared/math/modff16.h b/libc/shared/math/modff16.h
new file mode 100644
index 0000000000000..6cefd1dc99ae1
--- /dev/null
+++ b/libc/shared/math/modff16.h
@@ -0,0 +1,29 @@
+//===-- Shared modff16 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_MODFF16_H
+#define LLVM_LIBC_SHARED_MATH_MODFF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modff16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modff16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFF16_H
diff --git a/libc/shared/math/modfl.h b/libc/shared/math/modfl.h
new file mode 100644
index 0000000000000..9b900797d114f
--- /dev/null
+++ b/libc/shared/math/modfl.h
@@ -0,0 +1,23 @@
+//===-- Shared modfl 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_MODFL_H
+#define LLVM_LIBC_SHARED_MATH_MODFL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modfl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modfl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFL_H
diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 2a3e6deb3833e..1b8ee27273e5b 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -53,7 +53,7 @@ LIBC_INLINE constexpr T frexp(T x, int &exp) {
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE T modf(T x, T &iptr) {
+LIBC_INLINE constexpr T modf(T x, T &iptr) {
   FPBits<T> bits(x);
   if (bits.is_zero() || bits.is_nan()) {
     iptr = x;
diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h
index 30d6472085f6f..b74b8b7d1b18d 100644
--- a/libc/src/__support/FPUtil/generic/FMod.h
+++ b/libc/src/__support/FPUtil/generic/FMod.h
@@ -170,7 +170,7 @@ class FMod {
   using FPB = FPBits<T>;
   using StorageType = typename FPB::StorageType;
 
-  LIBC_INLINE static bool pre_check(T x, T y, T &out) {
+  LIBC_INLINE static constexpr bool pre_check(T x, T y, T &out) {
     using FPB = fputil::FPBits<T>;
     const T quiet_nan = FPB::quiet_nan().get_val();
     FPB sx(x), sy(y);
@@ -200,8 +200,8 @@ class FMod {
 
     if (LIBC_LIKELY(sx.uintval() <= sy.uintval())) {
       if (sx.uintval() < sy.uintval())
-        return sx;             // |x|<|y| return x
-      return FPB::zero();      // |x|=|y| return 0.0
+        return sx;        // |x|<|y| return x
+      return FPB::zero(); // |x|=|y| return 0.0
     }
 
     int e_x = sx.get_biased_exponent();
@@ -276,8 +276,8 @@ class FMod {
   }
 
 public:
-  LIBC_INLINE static T eval(T x, T y) {
-    if (T out; LIBC_UNLIKELY(pre_check(x, y, out)))
+  LIBC_INLINE static constexpr T eval(T x, T y) {
+    if (T out{}; LIBC_UNLIKELY(pre_check(x, y, out)))
       return out;
     FPB sx(x), sy(y);
     Sign sign = sx.sign();
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e930751e71f0b..762c1478f8dbd 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1275,6 +1275,62 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  fmod
+  HDRS
+    fmod.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmodbf16
+  HDRS
+    fmodbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmodf
+  HDRS
+    fmodf.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmodf128
+  HDRS
+    fmodf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmodf16
+  HDRS
+    fmodf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmodl
+  HDRS
+    fmodl.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.macros.config
+)
 
 add_header_library(
   llogbbf16
@@ -1296,6 +1352,63 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  modf
+  HDRS
+    modf.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  modfbf16
+  HDRS
+    modfbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  modff
+  HDRS
+    modff.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  modff128
+  HDRS
+    modff128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  modff16
+  HDRS
+    modff16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  modfl
+  HDRS
+    modfl.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   sincos_integer_utils
   HDRS
diff --git a/libc/src/__support/math/fmod.h b/libc/src/__support/math/fmod.h
new file mode 100644
index 0000000000000..79c48708d8aec
--- /dev/null
+++ b/libc/src/__support/math/fmod.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmod --------------------------*- 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_FMOD_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMOD_H
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double fmod(double x, double y) {
+  return fputil::generic::FMod<double>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMOD_H
diff --git a/libc/src/__support/math/fmodbf16.h b/libc/src/__support/math/fmodbf16.h
new file mode 100644
index 0000000000000..8f0bfbce4d16d
--- /dev/null
+++ b/libc/src/__support/math/fmodbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for fmodbf16 ----------------------*- 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_FMODBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODBF16_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 fmodbf16(bfloat16 x, bfloat16 y) {
+  return fputil::generic::FMod<bfloat16>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODBF16_H
diff --git a/libc/src/__support/math/fmodf.h b/libc/src/__support/math/fmodf.h
new file mode 100644
index 0000000000000..0209da81539d5
--- /dev/null
+++ b/libc/src/__support/math/fmodf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmodf -------------------------*- 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_FMODF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF_H
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fmodf(float x, float y) {
+  return fputil::generic::FMod<float, uint64_t>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF_H
diff --git a/libc/src/__support/math/fmodf128.h b/libc/src/__support/math/fmodf128.h
new file mode 100644
index 0000000000000..b15c1e17caab8
--- /dev/null
+++ b/libc/src/__support/math/fmodf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fmodf128 ----------------------*- 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_FMODF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 fmodf128(float128 x, float128 y) {
+  return fputil::generic::FMod<float128>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
diff --git a/libc/src/__support/math/fmodf16.h b/libc/src/__support/math/fmodf16.h
new file mode 100644
index 0000000000000..d69dfbb03d331
--- /dev/null
+++ b/libc/src/__support/math/fmodf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fmodf16 -----------------------*- 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_FMODF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 fmodf16(float16 x, float16 y) {
+  return fputil::generic::FMod<float16, uint32_t>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF16_H
diff --git a/libc/src/__support/math/fmodl.h b/libc/src/__support/math/fmodl.h
new file mode 100644
index 0000000000000..5625fb875dbaf
--- /dev/null
+++ b/libc/src/__support/math/fmodl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmodl -------------------------*- 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_FMODL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODL_H
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double fmodl(long double x, long double y) {
+  return fputil::generic::FMod<long double>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODL_H
diff --git a/libc/src/__support/math/modf.h b/libc/src/__support/math/modf.h
new file mode 100644
index 0000000000000..6625cd4c22ddc
--- /dev/null
+++ b/libc/src/__support/math/modf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for modf --------------------------*- 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_MODF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double modf(double x, double *iptr) {
+  return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODF_H
diff --git a/libc/src/__support/math/modfbf16.h b/libc/src/__support/math/modfbf16.h
new file mode 100644
index 0000000000000..ef8085204d1af
--- /dev/null
+++ b/libc/src/__support/math/modfbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for modfbf16 ----------------------*- 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_MODFBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFBF16_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 modfbf16(bfloat16 x, bfloat16 *iptr) {
+  return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFBF16_H
diff --git a/libc/src/__support/math/modff.h b/libc/src/__support/math/modff.h
new file mode 100644
index 0000000000000..6ddb5b539a178
--- /dev/null
+++ b/libc/src/__support/math/modff.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for modff -------------------------*- 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_MODFF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float modff(float x, float *iptr) {
+  return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFF_H
diff --git a/libc/src/__support/math/modff128.h b/libc/src/__support/math/modff128.h
new file mode 100644
index 0000000000000..69688dd255151
--- /dev/null
+++ b/libc/src/__support/math/modff128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for modff128 ----------------------*- 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_MODFF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 modff128(float128 x, float128 *iptr) {
+  return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFF128_H
diff --git a/libc/src/__support/math/modff16.h b/libc/src/__support/math/modff16.h
new file mode 100644
index 0000000000000..46fb98caee16b
--- /dev/null
+++ b/libc/src/__support/math/modff16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for modff16 -----------------------*- 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_MODFF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 modff16(float16 x, float16 *iptr) {
+  return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFF16_H
diff --git a/libc/src/__support/math/modfl.h b/libc/src/__support/math/modfl.h
new file mode 100644
index 0000000000000..d016a4c45237b
--- /dev/null
+++ b/libc/src/__support/math/modfl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for modfl -------------------------*- 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_MODFL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double modfl(long double x, long double *iptr) {
+  return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 54147d0a6ea22..cd0d053c1362f 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2001,7 +2001,7 @@ add_entrypoint_object(
   HDRS
     ../modf.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.modf
 )
 
 add_entrypoint_object(
@@ -2011,7 +2011,7 @@ add_entrypoint_object(
   HDRS
     ../modff.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.modff
 )
 
 add_entrypoint_object(
@@ -2021,7 +2021,7 @@ add_entrypoint_object(
   HDRS
     ../modfl.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.modfl
 )
 
 add_entrypoint_object(
@@ -2031,8 +2031,7 @@ add_entrypoint_object(
   HDRS
     ../modff16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.modff16
 )
 
 add_entrypoint_object(
@@ -2042,8 +2041,7 @@ add_entrypoint_object(
   HDRS
     ../modff128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.modff128
 )
 
 add_entrypoint_object(
@@ -2053,11 +2051,7 @@ add_entrypoint_object(
   HDRS
     ../modfbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.FPUtil.bfloat16
-    libc.src.__support.FPUtil.manipulation_functions
-    libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
+    libc.src.__support.math.modfbf16
 )
 
 add_entrypoint_object(
@@ -3475,7 +3469,7 @@ add_entrypoint_object(
   HDRS
     ../fmod.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.math.fmod
 )
 
 add_entrypoint_object(
@@ -3485,7 +3479,7 @@ add_entrypoint_object(
   HDRS
     ../fmodf.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.math.fmodf
 )
 
 add_entrypoint_object(
@@ -3495,7 +3489,7 @@ add_entrypoint_object(
   HDRS
     ../fmodl.h
   DEPENDS
-    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.math.fmodl
 )
 
 add_entrypoint_object(
@@ -3505,8 +3499,7 @@ add_entrypoint_object(
   HDRS
     ../fmodf16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.math.fmodf16
 )
 
 add_entrypoint_object(
@@ -3516,8 +3509,7 @@ add_entrypoint_object(
   HDRS
     ../fmodf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.math.fmodf128
 )
 
 add_entrypoint_object(
@@ -3527,11 +3519,7 @@ add_entrypoint_object(
   HDRS
     ../fmodbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.bfloat16
-    libc.src.__support.FPUtil.generic.fmod
+    libc.src.__support.math.fmodbf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/fmod.cpp b/libc/src/math/generic/fmod.cpp
index 010e66aa745ca..88b4676aeff36 100644
--- a/libc/src/math/generic/fmod.cpp
+++ b/libc/src/math/generic/fmod.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmod.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmod.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, fmod, (double x, double y)) {
-  return fputil::generic::FMod<double>::eval(x, y);
+  return math::fmod(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodbf16.cpp b/libc/src/math/generic/fmodbf16.cpp
index 902a680fe860c..4cd3d4df360e7 100644
--- a/libc/src/math/generic/fmodbf16.cpp
+++ b/libc/src/math/generic/fmodbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmodbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, fmodbf16, (bfloat16 x, bfloat16 y)) {
-  return fputil::generic::FMod<bfloat16>::eval(x, y);
+  return math::fmodbf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodf.cpp b/libc/src/math/generic/fmodf.cpp
index 1e1ef48895cc7..563d799d90081 100644
--- a/libc/src/math/generic/fmodf.cpp
+++ b/libc/src/math/generic/fmodf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmodf.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fmodf, (float x, float y)) {
-  return fputil::generic::FMod<float, uint64_t>::eval(x, y);
+  return math::fmodf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodf128.cpp b/libc/src/math/generic/fmodf128.cpp
index a7633bf9c2fff..c72ec7ec1cdf5 100644
--- a/libc/src/math/generic/fmodf128.cpp
+++ b/libc/src/math/generic/fmodf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmodf128.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, fmodf128, (float128 x, float128 y)) {
-  return fputil::generic::FMod<float128>::eval(x, y);
+  return math::fmodf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodf16.cpp b/libc/src/math/generic/fmodf16.cpp
index 2585639559496..121153a23a4b3 100644
--- a/libc/src/math/generic/fmodf16.cpp
+++ b/libc/src/math/generic/fmodf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmodf16.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, fmodf16, (float16 x, float16 y)) {
-  return fputil::generic::FMod<float16, uint32_t>::eval(x, y);
+  return math::fmodf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodl.cpp b/libc/src/math/generic/fmodl.cpp
index 1af8ffc976ddd..dbf87288c6d88 100644
--- a/libc/src/math/generic/fmodl.cpp
+++ b/libc/src/math/generic/fmodl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmodl.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, fmodl, (long double x, long double y)) {
-  return fputil::generic::FMod<long double>::eval(x, y);
+  return math::fmodl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modf.cpp b/libc/src/math/generic/modf.cpp
index ce56aa0bcf544..24a9d1c6a2364 100644
--- a/libc/src/math/generic/modf.cpp
+++ b/libc/src/math/generic/modf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/modf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, modf, (double x, double *iptr)) {
-  return fputil::modf(x, *iptr);
+  return math::modf(x, iptr);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modfbf16.cpp b/libc/src/math/generic/modfbf16.cpp
index 09458f6a2db40..8f5932220264a 100644
--- a/libc/src/math/generic/modfbf16.cpp
+++ b/libc/src/math/generic/modfbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/modfbf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modfbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, modfbf16, (bfloat16 x, bfloat16 *iptr)) {
-  return fputil::modf(x, *iptr);
+  return math::modfbf16(x, iptr);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modff.cpp b/libc/src/math/generic/modff.cpp
index c86a4fb279c7f..2576b0d294b57 100644
--- a/libc/src/math/generic/modff.cpp
+++ b/libc/src/math/generic/modff.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/modff.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modff.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, modff, (float x, float *iptr)) {
-  return fputil::modf(x, *iptr);
+  return math::modff(x, iptr);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modff128.cpp b/libc/src/math/generic/modff128.cpp
index 6f519a6901105..099bb2e907fb8 100644
--- a/libc/src/math/generic/modff128.cpp
+++ b/libc/src/math/generic/modff128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/modff128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modff128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, modff128, (float128 x, float128 *iptr)) {
-  return fputil::modf(x, *iptr);
+  return math::modff128(x, iptr);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modff16.cpp b/libc/src/math/generic/modff16.cpp
index 853fc55e26bab..c474672b90a70 100644
--- a/libc/src/math/generic/modff16.cpp
+++ b/libc/src/math/generic/modff16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/modff16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modff16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, modff16, (float16 x, float16 *iptr)) {
-  return fputil::modf(x, *iptr);
+  return math::modff16(x, iptr);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modfl.cpp b/libc/src/math/generic/modfl.cpp
index 8c9ab486b5aa3..320dff32a091d 100644
--- a/libc/src/math/generic/modfl.cpp
+++ b/libc/src/math/generic/modfl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/modfl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modfl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, modfl, (long double x, long double *iptr)) {
-  return fputil::modf(x, *iptr);
+  return math::modfl(x, iptr);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 8150b8c413071..b4237f347c44c 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -220,6 +220,12 @@ add_fp_unittest(
     libc.src.__support.math.fminimumf16
     libc.src.__support.math.fminimuml
     libc.src.__support.math.fminl
+    libc.src.__support.math.fmod
+    libc.src.__support.math.fmodbf16
+    libc.src.__support.math.fmodf
+    libc.src.__support.math.fmodf128
+    libc.src.__support.math.fmodf16
+    libc.src.__support.math.fmodl
     libc.src.__support.math.frexpf
     libc.src.__support.math.frexpf128
     libc.src.__support.math.frexpf16
@@ -272,6 +278,12 @@ add_fp_unittest(
     libc.src.__support.math.logbl
     libc.src.__support.math.logf16
     libc.src.__support.math.llogbl
+    libc.src.__support.math.modf
+    libc.src.__support.math.modfbf16
+    libc.src.__support.math.modff
+    libc.src.__support.math.modff128
+    libc.src.__support.math.modff16
+    libc.src.__support.math.modfl
     libc.src.__support.math.nextdown
     libc.src.__support.math.nextdownbf16
     libc.src.__support.math.nextdownf
@@ -451,10 +463,22 @@ add_fp_unittest(
     libc.src.__support.math.fminimumf16
     libc.src.__support.math.fminimuml
     libc.src.__support.math.fminl
+    libc.src.__support.math.fmod
+    libc.src.__support.math.fmodbf16
+    libc.src.__support.math.fmodf
+    libc.src.__support.math.fmodf128
+    libc.src.__support.math.fmodf16
+    libc.src.__support.math.fmodl
     libc.src.__support.math.llogbbf16
     libc.src.__support.math.log
     libc.src.__support.math.logbbf16
     libc.src.__support.math.ilogbbf16
+    libc.src.__support.math.modf
+    libc.src.__support.math.modfbf16
+    libc.src.__support.math.modff
+    libc.src.__support.math.modff128
+    libc.src.__support.math.modff16
+    libc.src.__support.math.modfl
     libc.src.__support.math.sqrtl
     libc.src.__support.math.ufromfp
     libc.src.__support.math.ufromfpbf16
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index da86e4e70e5c1..4c634c4616143 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -34,14 +34,19 @@ static_assert(0.0 == LIBC_NAMESPACE::shared::ufromfpx(0.0, 0, 32));
 static_assert(0.0 == LIBC_NAMESPACE::shared::fmaximum_mag(0.0, 0.0));
 static_assert(0.0 == LIBC_NAMESPACE::shared::fminimum_mag(0.0, 0.0));
 
-constexpr double totalorder_x = 0.0;
-constexpr double totalorder_y = 0.0;
+constexpr double TOTALORDER_X = 0.0;
+constexpr double TOTALORDER_Y = 0.0;
 static_assert(1 ==
-              LIBC_NAMESPACE::shared::totalorder(&totalorder_x, &totalorder_y));
-constexpr double totalordermag_x = 0.0;
-constexpr double totalordermag_y = 0.0;
-static_assert(1 == LIBC_NAMESPACE::shared::totalordermag(&totalordermag_x,
-                                                         &totalordermag_y));
+              LIBC_NAMESPACE::shared::totalorder(&TOTALORDER_X, &TOTALORDER_Y));
+constexpr double TOTALORDERMAG_X = 0.0;
+constexpr double TOTALORDERMAG_Y = 0.0;
+static_assert(1 == LIBC_NAMESPACE::shared::totalordermag(&TOTALORDERMAG_X,
+                                                         &TOTALORDERMAG_Y));
+static_assert(0.0 == LIBC_NAMESPACE::shared::fmod(4.0, 2.0));
+static_assert(0.0 == [] {
+  double iptr = 0;
+  return LIBC_NAMESPACE::shared::modf(0, &iptr);
+}());
 
 //===----------------------------------------------------------------------===//
 //                       Float Tests
@@ -64,15 +69,19 @@ static_assert(0.0f == LIBC_NAMESPACE::shared::ufromfpxf(0.0f, 0, 32));
 static_assert(0.0f == LIBC_NAMESPACE::shared::fmaximum_magf(0.0f, 0.0f));
 static_assert(0.0f == LIBC_NAMESPACE::shared::fminimum_magf(0.0f, 0.0f));
 
-constexpr float totalorderf_x = 0.0f;
-constexpr float totalorderf_y = 0.0f;
-static_assert(1 == LIBC_NAMESPACE::shared::totalorderf(&totalorderf_x,
-                                                       &totalorderf_y));
-constexpr float totalordermagf_x = 0.0f;
-constexpr float totalordermagf_y = 0.0f;
-static_assert(1 == LIBC_NAMESPACE::shared::totalordermagf(&totalordermagf_x,
-                                                          &totalordermagf_y));
-
+constexpr float TOTALORDERF_X = 0.0f;
+constexpr float TOTALORDERF_Y = 0.0f;
+static_assert(1 == LIBC_NAMESPACE::shared::totalorderf(&TOTALORDERF_X,
+                                                       &TOTALORDERF_Y));
+constexpr float TOTALORDERMAGF_X = 0.0f;
+constexpr float TOTALORDERMAGF_Y = 0.0f;
+static_assert(1 == LIBC_NAMESPACE::shared::totalordermagf(&TOTALORDERMAGF_X,
+                                                          &TOTALORDERMAGF_Y));
+static_assert(0.0f == LIBC_NAMESPACE::shared::fmodf(4.0f, 2.0f));
+static_assert(0.0f == [] {
+  float iptr = 0.0f;
+  return LIBC_NAMESPACE::shared::modff(0.0f, &iptr);
+}());
 //===----------------------------------------------------------------------===//
 //                       Float16 Tests
 //===----------------------------------------------------------------------===//
@@ -99,17 +108,21 @@ static_assert(0.0f16 ==
 static_assert(0.0f16 ==
               LIBC_NAMESPACE::shared::fminimum_magf16(0.0f16, 0.0f16));
 
-constexpr float16 totalorderf16_x = 0.0f16;
-constexpr float16 totalorderf16_y = 0.0f16;
-static_assert(1 == LIBC_NAMESPACE::shared::totalorderf16(&totalorderf16_x,
-                                                         &totalorderf16_y));
+constexpr float16 TOTALORDERF16_X = 0.0f16;
+constexpr float16 TOTALORDERF16_Y = 0.0f16;
+static_assert(1 == LIBC_NAMESPACE::shared::totalorderf16(&TOTALORDERF16_X,
+                                                         &TOTALORDERF16_Y));
 
-constexpr float16 totalordermagf16_x = 0.0f16;
-constexpr float16 totalordermagf16_y = 0.0f16;
+constexpr float16 TOTALORDERMAGF16_X = 0.0f16;
+constexpr float16 TOTALORDERMAGF16_Y = 0.0f16;
 static_assert(1 ==
-              LIBC_NAMESPACE::shared::totalordermagf16(&totalordermagf16_x,
-                                                       &totalordermagf16_y));
-
+              LIBC_NAMESPACE::shared::totalordermagf16(&TOTALORDERMAGF16_X,
+                                                       &TOTALORDERMAGF16_Y));
+static_assert(0.0f16 == LIBC_NAMESPACE::shared::fmodf16(4.0f16, 2.0f16));
+static_assert(0.0f16 == [] {
+  float16 iptr{};
+  return LIBC_NAMESPACE::shared::modff16(0.0f16, &iptr);
+}());
 #endif // LIBC_TYPES_HAS_FLOAT16
 
 //===----------------------------------------------------------------------===//
@@ -140,14 +153,20 @@ static_assert(0.0L == LIBC_NAMESPACE::shared::ufromfpxl(0.0L, 0, 32));
 static_assert(0.0L == LIBC_NAMESPACE::shared::fmaximum_magl(0.0L, 0.0L));
 static_assert(0.0L == LIBC_NAMESPACE::shared::fminimum_magl(0.0L, 0.0L));
 
-constexpr long double totalorderl_x = 0.0L;
-constexpr long double totalorderl_y = 0.0L;
-static_assert(1 == LIBC_NAMESPACE::shared::totalorderl(&totalorderl_x,
-                                                       &totalorderl_y));
-constexpr long double totalordermagl_x = 0.0L;
-constexpr long double totalordermagl_y = 0.0L;
-static_assert(1 == LIBC_NAMESPACE::shared::totalordermagl(&totalordermagl_x,
-                                                          &totalordermagl_y));
+constexpr long double TOTALORDERL_X = 0.0L;
+constexpr long double TOTALORDERL_Y = 0.0L;
+static_assert(1 == LIBC_NAMESPACE::shared::totalorderl(&TOTALORDERL_X,
+                                                       &TOTALORDERL_Y));
+constexpr long double TOTALORDERMAGL_X = 0.0L;
+constexpr long double TOTALORDERMAGL_Y = 0.0L;
+static_assert(1 == LIBC_NAMESPACE::shared::totalordermagl(&TOTALORDERMAGL_X,
+                                                          &TOTALORDERMAGL_Y));
+static_assert(0.0L == LIBC_NAMESPACE::shared::fmodl(4.0L, 2.0L));
+
+static_assert(0.0L == [] {
+  long double iptr{};
+  return LIBC_NAMESPACE::shared::modfl(0.0L, &iptr);
+}());
 
 #endif
 
@@ -201,15 +220,21 @@ static_assert(float128(0.0) ==
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::fminimum_magf128(float128(0.0),
                                                        float128(0.0)));
-constexpr float128 totalorderf128_x = float128(0.0);
-constexpr float128 totalorderf128_y = float128(0.0);
-static_assert(1 == LIBC_NAMESPACE::shared::totalorderf128(&totalorderf128_x,
-                                                          &totalorderf128_y));
-constexpr float128 totalordermagf128_x = float128(0.0);
-constexpr float128 totalordermagf128_y = float128(0.0);
+constexpr float128 TOTALORDERF128_X = float128(0.0);
+constexpr float128 TOTALORDERF128_Y = float128(0.0);
+static_assert(1 == LIBC_NAMESPACE::shared::totalorderf128(&TOTALORDERF128_X,
+                                                          &TOTALORDERF128_Y));
+constexpr float128 TOTALORDERMAGF128_X = float128(0.0);
+constexpr float128 TOTALORDERMAGF128_Y = float128(0.0);
 static_assert(1 ==
-              LIBC_NAMESPACE::shared::totalordermagf128(&totalordermagf128_x,
-                                                        &totalordermagf128_y));
+              LIBC_NAMESPACE::shared::totalordermagf128(&TOTALORDERMAGF128_X,
+                                                        &TOTALORDERMAGF128_Y));
+static_assert(0 ==
+              LIBC_NAMESPACE::shared::fmodf128(float128(4.0), float128(2.0)));
+static_assert(float128(0.0) == [] {
+  float128 iptr{};
+  return LIBC_NAMESPACE::shared::modff128(float128(0.0), &iptr);
+}());
 
 #endif // LIBC_TYPES_HAS_FLOAT128
 
@@ -262,14 +287,20 @@ static_assert(bfloat16(0.0) ==
               LIBC_NAMESPACE::shared::fminimum_magbf16(bfloat16(0.0),
                                                        bfloat16(0.0)));
 
-constexpr bfloat16 totalorderbf16_x = bfloat16(0.0);
-constexpr bfloat16 totalorderbf16_y = bfloat16(0.0);
-static_assert(1 == LIBC_NAMESPACE::shared::totalorderbf16(&totalorderbf16_x,
-                                                          &totalorderbf16_y));
-constexpr bfloat16 totalordermagbf16_x = bfloat16(0.0);
-constexpr bfloat16 totalordermagbf16_y = bfloat16(0.0);
+constexpr bfloat16 TOTALORDERBF16_X = bfloat16(0.0);
+constexpr bfloat16 TOTALORDERBF16_Y = bfloat16(0.0);
+static_assert(1 == LIBC_NAMESPACE::shared::totalorderbf16(&TOTALORDERBF16_X,
+                                                          &TOTALORDERBF16_Y));
+constexpr bfloat16 TOTALORDERMAGBF16_X = bfloat16(0.0);
+constexpr bfloat16 TOTALORDERMAGBF16_Y = bfloat16(0.0);
 static_assert(1 ==
-              LIBC_NAMESPACE::shared::totalordermagbf16(&totalordermagbf16_x,
-                                                        &totalordermagbf16_y));
+              LIBC_NAMESPACE::shared::totalordermagbf16(&TOTALORDERMAGBF16_X,
+                                                        &TOTALORDERMAGBF16_Y));
+static_assert(0 ==
+              LIBC_NAMESPACE::shared::fmodbf16(bfloat16(4.0), bfloat16(2.0)));
+static_assert(bfloat16(0.0) == [] {
+  bfloat16 iptr{};
+  return LIBC_NAMESPACE::shared::modfbf16(bfloat16(0.0), &iptr);
+}());
 
 TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {}
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 59015ff494134..e86c6e2cac607 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -124,6 +124,11 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   float16 totalordermagf16_y = 0.0f16;
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf16(&totalordermagf16_x,
                                                         &totalordermagf16_y));
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::fmodf16(1.0f16, 1.0f16));
+  float16 modff16_iptr = 0.0f16;
+  EXPECT_FP_EQ(0x0p+0f16,
+               LIBC_NAMESPACE::shared::modff16(0.0f16, &modff16_iptr));
+  EXPECT_FP_EQ(0.0f16, modff16_iptr);
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -252,6 +257,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   float totalordermagf_y = 0.0f;
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf(&totalordermagf_x,
                                                       &totalordermagf_y));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmodf(1.0f, 1.0f));
+  float modff_iptr = 0.0f;
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::modff(0.0f, &modff_iptr));
+  EXPECT_FP_EQ(0.0f, modff_iptr);
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -356,6 +365,10 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   double totalordermag_y = 0.0;
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermag(&totalordermag_x,
                                                      &totalordermag_y));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmod(1.0, 1.0));
+  double modf_iptr = 0.0;
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::modf(0.0, &modf_iptr));
+  EXPECT_FP_EQ(0.0, modf_iptr);
 }
 
 // TODO: Enable the tests when double-double type is supported.
@@ -441,6 +454,10 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   long double totalordermagl_y = 0.0L;
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagl(&totalordermagl_x,
                                                       &totalordermagl_y));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmodl(1.0L, 1.0L));
+  long double modfl_iptr = 0.0L;
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::modfl(0.0L, &modfl_iptr));
+  EXPECT_FP_EQ(0.0L, modfl_iptr);
 }
 
 #endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
@@ -575,6 +592,11 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   float128 totalordermagf128_y = float128(0.0);
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf128(&totalordermagf128_x,
                                                          &totalordermagf128_y));
+  LIBC_NAMESPACE::shared::fmodf128(float128(1.0), float128(1.0));
+  float128 modff128_iptr = float128(0.0);
+  EXPECT_FP_EQ(float128(0.0),
+               LIBC_NAMESPACE::shared::modff128(float128(0.0), &modff128_iptr));
+  EXPECT_FP_EQ(float128(0.0), modff128_iptr);
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -672,4 +694,9 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   bfloat16 totalordermagbf16_y = bfloat16(0.0);
   EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagbf16(&totalordermagbf16_x,
                                                          &totalordermagbf16_y));
+  LIBC_NAMESPACE::shared::fmodbf16(bfloat16(1.0), bfloat16(1.0));
+  bfloat16 modfbf16_iptr = bfloat16(0.0);
+  EXPECT_FP_EQ(bfloat16(0.0),
+               LIBC_NAMESPACE::shared::modfbf16(bfloat16(0.0), &modfbf16_iptr));
+  EXPECT_FP_EQ(bfloat16(0.0), modfbf16_iptr);
 }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 238cfae172ad4..80f853045dde9 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4476,6 +4476,63 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_fmod",
+    hdrs = ["src/__support/math/fmod.h"],
+    deps = [
+        ":__support_fputil_generic_fmod",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmodbf16",
+    hdrs = ["src/__support/math/fmodbf16.h"],
+    deps = [
+        ":__support_fputil_bfloat16",
+        ":__support_fputil_generic_fmod",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmodf",
+    hdrs = ["src/__support/math/fmodf.h"],
+    deps = [
+        ":__support_fputil_generic_fmod",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmodf128",
+    hdrs = ["src/__support/math/fmodf128.h"],
+    deps = [
+        ":__support_fputil_generic_fmod",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmodf16",
+    hdrs = ["src/__support/math/fmodf16.h"],
+    deps = [
+        ":__support_fputil_generic_fmod",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmodl",
+    hdrs = ["src/__support/math/fmodl.h"],
+    deps = [
+        ":__support_fputil_generic_fmod",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ilogbbf16",
     hdrs = ["src/__support/math/ilogbbf16.h"],
@@ -4486,6 +4543,63 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_modf",
+    hdrs = ["src/__support/math/modf.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_modfbf16",
+    hdrs = ["src/__support/math/modfbf16.h"],
+    deps = [
+        ":__support_fputil_bfloat16",
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_modff",
+    hdrs = ["src/__support/math/modff.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_modff128",
+    hdrs = ["src/__support/math/modff128.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_modff16",
+    hdrs = ["src/__support/math/modff16.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_modfl",
+    hdrs = ["src/__support/math/modfl.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_llogbbf16",
     hdrs = ["src/__support/math/llogbbf16.h"],
@@ -9121,38 +9235,43 @@ libc_math_function(
 
 libc_math_function(
     name = "fmod",
-    additional_deps = [":__support_fputil_generic_fmod"],
+    additional_deps = [
+        ":__support_math_fmod",
+    ],
 )
 
 libc_math_function(
     name = "fmodbf16",
     additional_deps = [
-        ":__support_fputil_bfloat16",
-        ":__support_fputil_generic_fmod",
+        ":__support_math_fmodbf16",
     ],
 )
 
 libc_math_function(
     name = "fmodf",
-    additional_deps = [":__support_fputil_generic_fmod"],
+    additional_deps = [
+        ":__support_math_fmodf",
+    ],
 )
 
 libc_math_function(
     name = "fmodl",
-    additional_deps = [":__support_fputil_generic_fmod"],
+    additional_deps = [
+        ":__support_math_fmodl",
+    ],
 )
 
 libc_math_function(
     name = "fmodf128",
     additional_deps = [
-        ":__support_fputil_generic_fmod",
+        ":__support_math_fmodf128",
     ],
 )
 
 libc_math_function(
     name = "fmodf16",
     additional_deps = [
-        ":__support_fputil_generic_fmod",
+        ":__support_math_fmodf16",
     ],
 )
 
@@ -9588,18 +9707,46 @@ libc_math_function(
     name = "lroundf16",
 )
 
-libc_math_function(name = "modf")
+libc_math_function(
+    name = "modf",
+    additional_deps = [
+        ":__support_math_modf",
+    ],
+)
+
+libc_math_function(
+    name = "modfbf16",
+    additional_deps = [
+        ":__support_math_modfbf16",
+    ],
+)
 
-libc_math_function(name = "modff")
+libc_math_function(
+    name = "modff",
+    additional_deps = [
+        ":__support_math_modff",
+    ],
+)
 
-libc_math_function(name = "modfl")
+libc_math_function(
+    name = "modfl",
+    additional_deps = [
+        ":__support_math_modfl",
+    ],
+)
 
 libc_math_function(
     name = "modff128",
+    additional_deps = [
+        ":__support_math_modff128",
+    ],
 )
 
 libc_math_function(
     name = "modff16",
+    additional_deps = [
+        ":__support_math_modff16",
+    ],
 )
 
 libc_math_function(



More information about the libc-commits mailing list