[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 20:22:17 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Anonmiraj (AnonMiraj)

<details>
<summary>Changes</summary>

Refactors the fmod-modf math family to be header-only.

part of: #<!-- -->147386

Target Functions:
  - fmod
  - fmodbf16
  - fmodf
  - fmodf128
  - fmodf16
  - fmodl
  - modf
  - modfbf16
  - modff
  - modff128
  - modff16
  - modfl

---

Patch is 53.58 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195406.diff


44 Files Affected:

- (modified) libc/shared/math.h (+12) 
- (added) libc/shared/math/fmod.h (+23) 
- (added) libc/shared/math/fmodbf16.h (+23) 
- (added) libc/shared/math/fmodf.h (+23) 
- (added) libc/shared/math/fmodf128.h (+29) 
- (added) libc/shared/math/fmodf16.h (+29) 
- (added) libc/shared/math/fmodl.h (+23) 
- (added) libc/shared/math/modf.h (+23) 
- (added) libc/shared/math/modfbf16.h (+23) 
- (added) libc/shared/math/modff.h (+23) 
- (added) libc/shared/math/modff128.h (+29) 
- (added) libc/shared/math/modff16.h (+29) 
- (added) libc/shared/math/modfl.h (+23) 
- (modified) libc/src/__support/FPUtil/generic/FMod.h (+5-5) 
- (modified) libc/src/__support/math/CMakeLists.txt (+113) 
- (added) libc/src/__support/math/fmod.h (+25) 
- (added) libc/src/__support/math/fmodbf16.h (+26) 
- (added) libc/src/__support/math/fmodf.h (+25) 
- (added) libc/src/__support/math/fmodf128.h (+31) 
- (added) libc/src/__support/math/fmodf16.h (+31) 
- (added) libc/src/__support/math/fmodl.h (+25) 
- (added) libc/src/__support/math/modf.h (+25) 
- (added) libc/src/__support/math/modfbf16.h (+26) 
- (added) libc/src/__support/math/modff.h (+25) 
- (added) libc/src/__support/math/modff128.h (+31) 
- (added) libc/src/__support/math/modff16.h (+31) 
- (added) libc/src/__support/math/modfl.h (+25) 
- (modified) libc/src/math/generic/CMakeLists.txt (+12-24) 
- (modified) libc/src/math/generic/fmod.cpp (+2-4) 
- (modified) libc/src/math/generic/fmodbf16.cpp (+2-5) 
- (modified) libc/src/math/generic/fmodf.cpp (+2-4) 
- (modified) libc/src/math/generic/fmodf128.cpp (+2-4) 
- (modified) libc/src/math/generic/fmodf16.cpp (+2-4) 
- (modified) libc/src/math/generic/fmodl.cpp (+2-4) 
- (modified) libc/src/math/generic/modf.cpp (+2-4) 
- (modified) libc/src/math/generic/modfbf16.cpp (+2-5) 
- (modified) libc/src/math/generic/modff.cpp (+2-4) 
- (modified) libc/src/math/generic/modff128.cpp (+2-4) 
- (modified) libc/src/math/generic/modff16.cpp (+2-4) 
- (modified) libc/src/math/generic/modfl.cpp (+2-4) 
- (modified) libc/test/shared/CMakeLists.txt (+24) 
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+8) 
- (modified) libc/test/shared/shared_math_test.cpp (+29) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+157-10) 


``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 6d2b573244c0c..7b34492586467 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -211,6 +211,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"
@@ -262,6 +268,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/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 dad34b0023154..d36b6d9196e75 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1157,6 +1157,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
@@ -1178,6 +1234,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 ...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list