[libc-commits] [libc] [llvm] [libc][math] Refactor nexttoward family to header-only (PR #181685)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 16 07:28:55 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Anonmiraj (AnonMiraj)
<details>
<summary>Changes</summary>
Refactors the nexttoward math family to be header-only.
Closes https://github.com/llvm/llvm-project/issues/181684
---
Patch is 23.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/181685.diff
21 Files Affected:
- (modified) libc/shared/math.h (+5)
- (added) libc/shared/math/nexttoward.h (+23)
- (added) libc/shared/math/nexttowardbf16.h (+23)
- (added) libc/shared/math/nexttowardf.h (+23)
- (added) libc/shared/math/nexttowardf16.h (+29)
- (added) libc/shared/math/nexttowardl.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+47)
- (added) libc/src/__support/math/nexttoward.h (+28)
- (added) libc/src/__support/math/nexttowardbf16.h (+28)
- (added) libc/src/__support/math/nexttowardf.h (+28)
- (added) libc/src/__support/math/nexttowardf16.h (+34)
- (added) libc/src/__support/math/nexttowardl.h (+28)
- (modified) libc/src/math/generic/CMakeLists.txt (+5-10)
- (modified) libc/src/math/generic/nexttoward.cpp (+2-6)
- (modified) libc/src/math/generic/nexttowardbf16.cpp (+2-6)
- (modified) libc/src/math/generic/nexttowardf.cpp (+2-6)
- (modified) libc/src/math/generic/nexttowardf16.cpp (+2-6)
- (modified) libc/src/math/generic/nexttowardl.cpp (+2-6)
- (modified) libc/test/shared/CMakeLists.txt (+5)
- (modified) libc/test/shared/shared_math_test.cpp (+12)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+71-4)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 93f7d6a8156cf..8dc3ade9515b9 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -111,6 +111,11 @@
#include "math/logbf16.h"
#include "math/logf.h"
#include "math/logf16.h"
+#include "math/nexttoward.h"
+#include "math/nexttowardbf16.h"
+#include "math/nexttowardf.h"
+#include "math/nexttowardf16.h"
+#include "math/nexttowardl.h"
#include "math/pow.h"
#include "math/powf.h"
#include "math/rsqrtf.h"
diff --git a/libc/shared/math/nexttoward.h b/libc/shared/math/nexttoward.h
new file mode 100644
index 0000000000000..e75a5172aeaf4
--- /dev/null
+++ b/libc/shared/math/nexttoward.h
@@ -0,0 +1,23 @@
+//===-- Shared nexttoward 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_NEXTTOWARD_H
+#define LLVM_LIBC_SHARED_MATH_NEXTTOWARD_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nexttoward.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nexttoward;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTTOWARD_H
diff --git a/libc/shared/math/nexttowardbf16.h b/libc/shared/math/nexttowardbf16.h
new file mode 100644
index 0000000000000..46059754b571b
--- /dev/null
+++ b/libc/shared/math/nexttowardbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nexttowardbf16 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_NEXTTOWARDBF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTTOWARDBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nexttowardbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nexttowardbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTTOWARDBF16_H
diff --git a/libc/shared/math/nexttowardf.h b/libc/shared/math/nexttowardf.h
new file mode 100644
index 0000000000000..156e6df4fe52b
--- /dev/null
+++ b/libc/shared/math/nexttowardf.h
@@ -0,0 +1,23 @@
+//===-- Shared nexttowardf 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_NEXTTOWARDF_H
+#define LLVM_LIBC_SHARED_MATH_NEXTTOWARDF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nexttowardf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nexttowardf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTTOWARDF_H
diff --git a/libc/shared/math/nexttowardf16.h b/libc/shared/math/nexttowardf16.h
new file mode 100644
index 0000000000000..7753943d7a349
--- /dev/null
+++ b/libc/shared/math/nexttowardf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nexttowardf16 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_NEXTTOWARDF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTTOWARDF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nexttowardf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nexttowardf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTTOWARDF16_H
diff --git a/libc/shared/math/nexttowardl.h b/libc/shared/math/nexttowardl.h
new file mode 100644
index 0000000000000..ebb727f8418a7
--- /dev/null
+++ b/libc/shared/math/nexttowardl.h
@@ -0,0 +1,23 @@
+//===-- Shared nexttowardl 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_NEXTTOWARDL_H
+#define LLVM_LIBC_SHARED_MATH_NEXTTOWARDL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nexttowardl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nexttowardl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTTOWARDL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index aaab78c01a891..15f8c4699a470 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1255,6 +1255,53 @@ add_header_library(
libc.src.__support.common
libc.src.__support.macros.config
)
+add_header_library(
+ nexttoward
+ HDRS
+ nexttoward.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nexttowardbf16
+ HDRS
+ nexttowardbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nexttowardf
+ HDRS
+ nexttowardf.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nexttowardf16
+ HDRS
+ nexttowardf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nexttowardl
+ HDRS
+ nexttowardl.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
add_header_library(
range_reduction_double
diff --git a/libc/src/__support/math/nexttoward.h b/libc/src/__support/math/nexttoward.h
new file mode 100644
index 0000000000000..7f9ba9df3a816
--- /dev/null
+++ b/libc/src/__support/math/nexttoward.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for nexttoward --------------------*- 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_NEXTTOWARD_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARD_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double nexttoward(double x, long double y) {
+ // We can reuse the nextafter implementation because the internal nextafter is
+ // templated on the types of the arguments.
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARD_H
diff --git a/libc/src/__support/math/nexttowardbf16.h b/libc/src/__support/math/nexttowardbf16.h
new file mode 100644
index 0000000000000..3d0d278f6801f
--- /dev/null
+++ b/libc/src/__support/math/nexttowardbf16.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for nexttowardbf16 ----------------*- 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_NEXTTOWARDBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDBF16_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 nexttowardbf16(bfloat16 x, long double y) {
+ // nextafter<T, U> where T != U is nexttoward
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDBF16_H
diff --git a/libc/src/__support/math/nexttowardf.h b/libc/src/__support/math/nexttowardf.h
new file mode 100644
index 0000000000000..575b50744cd2f
--- /dev/null
+++ b/libc/src/__support/math/nexttowardf.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for nexttowardf -------------------*- 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_NEXTTOWARDF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float nexttowardf(float x, long double y) {
+ // We can reuse the nextafter implementation because the internal nextafter is
+ // templated on the types of the arguments.
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDF_H
diff --git a/libc/src/__support/math/nexttowardf16.h b/libc/src/__support/math/nexttowardf16.h
new file mode 100644
index 0000000000000..9e5b3ef049b2d
--- /dev/null
+++ b/libc/src/__support/math/nexttowardf16.h
@@ -0,0 +1,34 @@
+//===-- Implementation header for nexttowardf16 -----------------*- 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_NEXTTOWARDF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDF16_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 nexttowardf16(float16 x, long double y) {
+ // We can reuse the nextafter implementation because the internal nextafter is
+ // templated on the types of the arguments.
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDF16_H
diff --git a/libc/src/__support/math/nexttowardl.h b/libc/src/__support/math/nexttowardl.h
new file mode 100644
index 0000000000000..b1a7a66f69886
--- /dev/null
+++ b/libc/src/__support/math/nexttowardl.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for nexttowardl -------------------*- 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_NEXTTOWARDL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE long double nexttowardl(long double x, long double y) {
+ // We can reuse the nextafter implementation because the internal nextafter is
+ // templated on the types of the arguments.
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTTOWARDL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 75b51b4587bea..2018be0a99de6 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3479,7 +3479,7 @@ add_entrypoint_object(
HDRS
../nexttoward.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nexttoward
)
add_entrypoint_object(
@@ -3489,7 +3489,7 @@ add_entrypoint_object(
HDRS
../nexttowardf.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nexttowardf
)
add_entrypoint_object(
@@ -3499,7 +3499,7 @@ add_entrypoint_object(
HDRS
../nexttowardl.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nexttowardl
)
add_entrypoint_object(
@@ -3509,8 +3509,7 @@ add_entrypoint_object(
HDRS
../nexttowardf16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nexttowardf16
)
add_entrypoint_object(
@@ -3520,11 +3519,7 @@ add_entrypoint_object(
HDRS
../nexttowardbf16.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.nexttowardbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/nexttoward.cpp b/libc/src/math/generic/nexttoward.cpp
index 7102a0afe38f3..a5536270bccc7 100644
--- a/libc/src/math/generic/nexttoward.cpp
+++ b/libc/src/math/generic/nexttoward.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nexttoward.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nexttoward.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, nexttoward, (double x, long double y)) {
- // We can reuse the nextafter implementation because the internal nextafter is
- // templated on the types of the arguments.
- return fputil::nextafter(x, y);
+ return math::nexttoward(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nexttowardbf16.cpp b/libc/src/math/generic/nexttowardbf16.cpp
index 3deab87575939..90078219b722c 100644
--- a/libc/src/math/generic/nexttowardbf16.cpp
+++ b/libc/src/math/generic/nexttowardbf16.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nexttowardbf16.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/nexttowardbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, nexttowardbf16, (bfloat16 x, long double y)) {
- // nextafter<T, U> where T != U is nexttoward
- return fputil::nextafter(x, y);
+ return math::nexttowardbf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nexttowardf.cpp b/libc/src/math/generic/nexttowardf.cpp
index 095a7af8c2611..5a4e1d618a1d3 100644
--- a/libc/src/math/generic/nexttowardf.cpp
+++ b/libc/src/math/generic/nexttowardf.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nexttowardf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nexttowardf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, nexttowardf, (float x, long double y)) {
- // We can reuse the nextafter implementation because the internal nextafter is
- // templated on the types of the arguments.
- return fputil::nextafter(x, y);
+ return math::nexttowardf(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nexttowardf16.cpp b/libc/src/math/generic/nexttowardf16.cpp
index 75218b1dcf812..4cd95852fc255 100644
--- a/libc/src/math/generic/nexttowardf16.cpp
+++ b/libc/src/math/generic/nexttowardf16.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nexttowardf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nexttowardf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, nexttowardf16, (float16 x, long double y)) {
- // We can reuse the nextafter implementation because the internal nextafter is
- // templated on the types of the arguments.
- return fputil::nextafter(x, y);
+ return math::nexttowardf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nexttowardl.cpp b/libc/src/math/generic/nexttowardl.cpp
index b20868956dbc8..24ca7b5af3a63 100644
--- a/libc/src/math/generic/nexttowardl.cpp
+++ b/libc/src/math/generic/nexttowardl.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nexttowardl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nexttowardl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, nexttowardl, (long double x, long double y)) {
- // We can reuse the nextafter implementation because the internal nextafter is
- // templated on the types of the arguments.
- return fputil::nextafter(x, y);
+ return math::nexttowardl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 9dfbedee66a33..a76e1d5e6bd14 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -108,6 +108,11 @@ add_fp_unittest(
libc.src.__support.math.llogbf16
libc.src.__support.math.logf16
libc.src.__support.math.llogbl
+ libc.src.__support.math.nexttoward
+ libc.src.__support.math.nexttowardbf16
+ libc.src.__support.math.nexttowardf
+ libc.src.__support.math.nexttowardf16
+ libc.src.__support.math.nexttowardl
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 2d7ee388f754d..5211fda2ca5e7 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -81,6 +81,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef16(&canonicalizef16_cx,
&canonicalizef16_x));
EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
+
+ EXPECT_FP_EQ(0x0p+0f16,
+ LIBC_NAMESPACE::shared::nexttowardf16(0.0f16, 0.0f16));
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -142,6 +145,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef(&canonicalizef_cx,
&canonicalizef_x));
EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
+
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::nexttowardf(0.0f, 0.0f));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -174,6 +179,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_EQ(0...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/181685
More information about the libc-commits
mailing list