[libc-commits] [libc] 7e39b28 - [libc][math] Refactor nextafter family to header-only (#181673)

via libc-commits libc-commits at lists.llvm.org
Thu Feb 26 15:53:02 PST 2026


Author: Anonmiraj
Date: 2026-02-27T01:52:57+02:00
New Revision: 7e39b280e8607e4bd09b87fb3271963803b4d02f

URL: https://github.com/llvm/llvm-project/commit/7e39b280e8607e4bd09b87fb3271963803b4d02f
DIFF: https://github.com/llvm/llvm-project/commit/7e39b280e8607e4bd09b87fb3271963803b4d02f.diff

LOG: [libc][math] Refactor nextafter family to header-only (#181673)

closes #181672

Added: 
    libc/shared/math/nextafter.h
    libc/shared/math/nextafterbf16.h
    libc/shared/math/nextafterf.h
    libc/shared/math/nextafterf128.h
    libc/shared/math/nextafterf16.h
    libc/shared/math/nextafterl.h
    libc/src/__support/math/nextafter.h
    libc/src/__support/math/nextafterbf16.h
    libc/src/__support/math/nextafterf.h
    libc/src/__support/math/nextafterf128.h
    libc/src/__support/math/nextafterf16.h
    libc/src/__support/math/nextafterl.h

Modified: 
    libc/shared/math.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/nextafter.cpp
    libc/src/math/generic/nextafterbf16.cpp
    libc/src/math/generic/nextafterf.cpp
    libc/src/math/generic/nextafterf128.cpp
    libc/src/math/generic/nextafterf16.cpp
    libc/src/math/generic/nextafterl.cpp
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_math_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/shared/math.h b/libc/shared/math.h
index c1cf20ac25f96..c1243e1937bcc 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -170,6 +170,12 @@
 #include "math/logbl.h"
 #include "math/logf.h"
 #include "math/logf16.h"
+#include "math/nextafter.h"
+#include "math/nextafterbf16.h"
+#include "math/nextafterf.h"
+#include "math/nextafterf128.h"
+#include "math/nextafterf16.h"
+#include "math/nextafterl.h"
 #include "math/nextdown.h"
 #include "math/nextdownbf16.h"
 #include "math/nextdownf.h"

diff  --git a/libc/shared/math/nextafter.h b/libc/shared/math/nextafter.h
new file mode 100644
index 0000000000000..07addbba337e4
--- /dev/null
+++ b/libc/shared/math/nextafter.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafter 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_NEXTAFTER_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTER_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafter.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafter;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTER_H

diff  --git a/libc/shared/math/nextafterbf16.h b/libc/shared/math/nextafterbf16.h
new file mode 100644
index 0000000000000..52073b1fde409
--- /dev/null
+++ b/libc/shared/math/nextafterbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafterbf16 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_NEXTAFTERBF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERBF16_H

diff  --git a/libc/shared/math/nextafterf.h b/libc/shared/math/nextafterf.h
new file mode 100644
index 0000000000000..0933cd30679e6
--- /dev/null
+++ b/libc/shared/math/nextafterf.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafterf 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_NEXTAFTERF_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF_H

diff  --git a/libc/shared/math/nextafterf128.h b/libc/shared/math/nextafterf128.h
new file mode 100644
index 0000000000000..e25c2ea1fee56
--- /dev/null
+++ b/libc/shared/math/nextafterf128.h
@@ -0,0 +1,29 @@
+//===-- Shared nextafterf128 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_NEXTAFTERF128_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H

diff  --git a/libc/shared/math/nextafterf16.h b/libc/shared/math/nextafterf16.h
new file mode 100644
index 0000000000000..c90ac3b9ae69d
--- /dev/null
+++ b/libc/shared/math/nextafterf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nextafterf16 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_NEXTAFTERF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF16_H

diff  --git a/libc/shared/math/nextafterl.h b/libc/shared/math/nextafterl.h
new file mode 100644
index 0000000000000..4de0f1c25c02f
--- /dev/null
+++ b/libc/shared/math/nextafterl.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafterl 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_NEXTAFTERL_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERL_H

diff  --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 75a55c2939e19..44b6a10352537 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1848,6 +1848,63 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  nextafter
+  HDRS
+    nextafter.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextafterbf16
+  HDRS
+    nextafterbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextafterf
+  HDRS
+    nextafterf.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextafterf128
+  HDRS
+    nextafterf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextafterf16
+  HDRS
+    nextafterf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextafterl
+  HDRS
+    nextafterl.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
 add_header_library(
  nexttoward
   HDRS

diff  --git a/libc/src/__support/math/nextafter.h b/libc/src/__support/math/nextafter.h
new file mode 100644
index 0000000000000..beb2fc9da057c
--- /dev/null
+++ b/libc/src/__support/math/nextafter.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextafter ---------------------*- 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_NEXTAFTER_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTER_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double nextafter(double x, double y) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTER_H

diff  --git a/libc/src/__support/math/nextafterbf16.h b/libc/src/__support/math/nextafterbf16.h
new file mode 100644
index 0000000000000..26679e2079045
--- /dev/null
+++ b/libc/src/__support/math/nextafterbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for nextafterbf16 -----------------*- 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_NEXTAFTERBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERBF16_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 bfloat16 nextafterbf16(bfloat16 x, bfloat16 y) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERBF16_H

diff  --git a/libc/src/__support/math/nextafterf.h b/libc/src/__support/math/nextafterf.h
new file mode 100644
index 0000000000000..7d8a0f203879b
--- /dev/null
+++ b/libc/src/__support/math/nextafterf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextafterf --------------------*- 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_NEXTAFTERF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float nextafterf(float x, float y) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF_H

diff  --git a/libc/src/__support/math/nextafterf128.h b/libc/src/__support/math/nextafterf128.h
new file mode 100644
index 0000000000000..b13b913c506fe
--- /dev/null
+++ b/libc/src/__support/math/nextafterf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for nextafterf128 -----------------*- 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_NEXTAFTERF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_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 float128 nextafterf128(float128 x, float128 y) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_H

diff  --git a/libc/src/__support/math/nextafterf16.h b/libc/src/__support/math/nextafterf16.h
new file mode 100644
index 0000000000000..631790b44cb73
--- /dev/null
+++ b/libc/src/__support/math/nextafterf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for nextafterf16 ------------------*- 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_NEXTAFTERF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF16_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 float16 nextafterf16(float16 x, float16 y) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF16_H

diff  --git a/libc/src/__support/math/nextafterl.h b/libc/src/__support/math/nextafterl.h
new file mode 100644
index 0000000000000..cf2c2e6da5fb4
--- /dev/null
+++ b/libc/src/__support/math/nextafterl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextafterl --------------------*- 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_NEXTAFTERL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE long double nextafterl(long double x, long double y) {
+  return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERL_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f8834c5c12705..516817be16cf6 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3345,7 +3345,7 @@ add_entrypoint_object(
   HDRS
     ../nextafter.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextafter
 )
 
 add_entrypoint_object(
@@ -3355,7 +3355,7 @@ add_entrypoint_object(
   HDRS
     ../nextafterf.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextafterf
 )
 
 add_entrypoint_object(
@@ -3365,7 +3365,7 @@ add_entrypoint_object(
   HDRS
     ../nextafterl.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextafterl
 )
 
 add_entrypoint_object(
@@ -3375,8 +3375,7 @@ add_entrypoint_object(
   HDRS
     ../nextafterf16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextafterf16
 )
 
 add_entrypoint_object(
@@ -3386,8 +3385,7 @@ add_entrypoint_object(
   HDRS
     ../nextafterf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextafterf128
 )
 
 add_entrypoint_object(
@@ -3397,11 +3395,7 @@ add_entrypoint_object(
   HDRS
     ../nextafterbf16.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.nextafterbf16
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/nextafter.cpp b/libc/src/math/generic/nextafter.cpp
index ff35c86930eab..bbb98576e0b40 100644
--- a/libc/src/math/generic/nextafter.cpp
+++ b/libc/src/math/generic/nextafter.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafter.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafter.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, nextafter, (double x, double y)) {
-  return fputil::nextafter(x, y);
+  return math::nextafter(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/nextafterbf16.cpp b/libc/src/math/generic/nextafterbf16.cpp
index e21a2dcb3d664..42887c9eba274 100644
--- a/libc/src/math/generic/nextafterbf16.cpp
+++ b/libc/src/math/generic/nextafterbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafterbf16.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/nextafterbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, nextafterbf16, (bfloat16 x, bfloat16 y)) {
-  return fputil::nextafter(x, y);
+  return math::nextafterbf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/nextafterf.cpp b/libc/src/math/generic/nextafterf.cpp
index fd8ca02895b67..eca649704b759 100644
--- a/libc/src/math/generic/nextafterf.cpp
+++ b/libc/src/math/generic/nextafterf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafterf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, nextafterf, (float x, float y)) {
-  return fputil::nextafter(x, y);
+  return math::nextafterf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/nextafterf128.cpp b/libc/src/math/generic/nextafterf128.cpp
index c774f10b88ccd..3363db898fe0b 100644
--- a/libc/src/math/generic/nextafterf128.cpp
+++ b/libc/src/math/generic/nextafterf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafterf128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, nextafterf128, (float128 x, float128 y)) {
-  return fputil::nextafter(x, y);
+  return math::nextafterf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/nextafterf16.cpp b/libc/src/math/generic/nextafterf16.cpp
index 70adc9c0800d3..69fe584eae1af 100644
--- a/libc/src/math/generic/nextafterf16.cpp
+++ b/libc/src/math/generic/nextafterf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafterf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, nextafterf16, (float16 x, float16 y)) {
-  return fputil::nextafter(x, y);
+  return math::nextafterf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/nextafterl.cpp b/libc/src/math/generic/nextafterl.cpp
index 5dafd63b77560..e888f88c36a07 100644
--- a/libc/src/math/generic/nextafterl.cpp
+++ b/libc/src/math/generic/nextafterl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafterl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, nextafterl, (long double x, long double y)) {
-  return fputil::nextafter(x, y);
+  return math::nextafterl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 490e498aaf9e8..e23b477d03009 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -185,6 +185,12 @@ add_fp_unittest(
     libc.src.__support.math.nexttowardf
     libc.src.__support.math.nexttowardf16
     libc.src.__support.math.nexttowardl
+    libc.src.__support.math.nextafter
+    libc.src.__support.math.nextafterbf16
+    libc.src.__support.math.nextafterf
+    libc.src.__support.math.nextafterf16
+    libc.src.__support.math.nextafterl
+    libc.src.__support.math.nextafterf128
     libc.src.__support.math.pow
     libc.src.__support.math.powf
     libc.src.__support.math.rsqrtf

diff  --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 43ff7610e384b..978418714cdfe 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -135,6 +135,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf16(0.0f16));
   EXPECT_FP_EQ(0x0p+0f16,
                LIBC_NAMESPACE::shared::nexttowardf16(0.0f16, 0.0f16));
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::nextafterf16(0.0f16, 0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -219,6 +220,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   float min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf(0.0f));
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::nexttowardf(0.0f, 0.0f));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::nextafterf(0.0f, 0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -279,6 +281,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   double min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextup(0.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::nexttoward(0.0, 0.0));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::nextafter(0.0, 0.0));
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -318,6 +321,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   long double min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupl(0.0L));
   EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::nexttowardl(0.0L, 0.0L));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::nextafterl(0.0L, 0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -384,6 +388,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
   float128 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128(
+                                  float128(0.0), float128(0.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -431,4 +437,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
 
   EXPECT_FP_EQ(bfloat16(0.0),
                LIBC_NAMESPACE::shared::nexttowardbf16(bfloat16(0.0), 0.0L));
+  EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::nextafterbf16(
+                                  bfloat16(0.0), bfloat16(0.0)));
 }

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c31c1e18f1deb..b700e0fe99465 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4107,6 +4107,63 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_nextafter",
+    hdrs = ["src/__support/math/nextafter.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextafterbf16",
+    hdrs = ["src/__support/math/nextafterbf16.h"],
+    deps = [
+        ":__support_fputil_bfloat16",
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextafterf",
+    hdrs = ["src/__support/math/nextafterf.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextafterf128",
+    hdrs = ["src/__support/math/nextafterf128.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextafterf16",
+    hdrs = ["src/__support/math/nextafterf16.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextafterl",
+    hdrs = ["src/__support/math/nextafterl.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_nextdown",
     hdrs = ["src/__support/math/nextdown.h"],
@@ -7196,18 +7253,46 @@ libc_math_function(
     name = "nearbyintf16",
 )
 
-libc_math_function(name = "nextafter")
+libc_math_function(
+    name = "nextafter",
+    additional_deps = [
+        ":__support_math_nextafter",
+    ],
+)
 
-libc_math_function(name = "nextafterf")
+libc_math_function(
+    name = "nextafterbf16",
+    additional_deps = [
+        ":__support_math_nextafterbf16",
+    ],
+)
+
+libc_math_function(
+    name = "nextafterf",
+    additional_deps = [
+        ":__support_math_nextafterf",
+    ],
+)
 
-libc_math_function(name = "nextafterl")
+libc_math_function(
+    name = "nextafterl",
+    additional_deps = [
+        ":__support_math_nextafterl",
+    ],
+)
 
 libc_math_function(
     name = "nextafterf128",
+    additional_deps = [
+        ":__support_math_nextafterf128",
+    ],
 )
 
 libc_math_function(
     name = "nextafterf16",
+    additional_deps = [
+        ":__support_math_nextafterf16",
+    ],
 )
 
 libc_math_function(


        


More information about the libc-commits mailing list