[libc-commits] [libc] [llvm] [libc][math] Refactor rint-nearbyint family to header-only (PR #195577)
via libc-commits
libc-commits at lists.llvm.org
Sun May 3 19:28:59 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Anonmiraj (AnonMiraj)
<details>
<summary>Changes</summary>
Refactors the rint-nearbyint math family to be header-only.
part of: #<!-- -->147386
Target Functions:
- nearbyint
- nearbyintbf16
- nearbyintf
- nearbyintf128
- nearbyintf16
- nearbyintl
- rint
- rintbf16
- rintf
- rintf128
- rintf16
- rintl
---
Patch is 55.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195577.diff
43 Files Affected:
- (modified) libc/shared/math.h (+12)
- (added) libc/shared/math/nearbyint.h (+23)
- (added) libc/shared/math/nearbyintbf16.h (+23)
- (added) libc/shared/math/nearbyintf.h (+23)
- (added) libc/shared/math/nearbyintf128.h (+29)
- (added) libc/shared/math/nearbyintf16.h (+29)
- (added) libc/shared/math/nearbyintl.h (+23)
- (added) libc/shared/math/rint.h (+23)
- (added) libc/shared/math/rintbf16.h (+23)
- (added) libc/shared/math/rintf.h (+23)
- (added) libc/shared/math/rintf128.h (+29)
- (added) libc/shared/math/rintf16.h (+29)
- (added) libc/shared/math/rintl.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+123)
- (added) libc/src/__support/math/nearbyint.h (+25)
- (added) libc/src/__support/math/nearbyintbf16.h (+26)
- (added) libc/src/__support/math/nearbyintf.h (+25)
- (added) libc/src/__support/math/nearbyintf128.h (+31)
- (added) libc/src/__support/math/nearbyintf16.h (+31)
- (added) libc/src/__support/math/nearbyintl.h (+25)
- (added) libc/src/__support/math/rint.h (+29)
- (added) libc/src/__support/math/rintbf16.h (+26)
- (added) libc/src/__support/math/rintf.h (+29)
- (added) libc/src/__support/math/rintf128.h (+31)
- (added) libc/src/__support/math/rintf16.h (+38)
- (added) libc/src/__support/math/rintl.h (+25)
- (modified) libc/src/math/generic/CMakeLists.txt (+12-32)
- (modified) libc/src/math/generic/nearbyint.cpp (+2-6)
- (modified) libc/src/math/generic/nearbyintbf16.cpp (+2-5)
- (modified) libc/src/math/generic/nearbyintf.cpp (+2-6)
- (modified) libc/src/math/generic/nearbyintf128.cpp (+2-4)
- (modified) libc/src/math/generic/nearbyintf16.cpp (+2-4)
- (modified) libc/src/math/generic/nearbyintl.cpp (+2-4)
- (modified) libc/src/math/generic/rint.cpp (+2-10)
- (modified) libc/src/math/generic/rintbf16.cpp (+2-5)
- (modified) libc/src/math/generic/rintf.cpp (+2-10)
- (modified) libc/src/math/generic/rintf128.cpp (+2-4)
- (modified) libc/src/math/generic/rintf16.cpp (+2-13)
- (modified) libc/src/math/generic/rintl.cpp (+2-4)
- (modified) libc/test/shared/CMakeLists.txt (+24)
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+14)
- (modified) libc/test/shared/shared_math_test.cpp (+14)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+175-8)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index ec1cfba7c0834..bed4279f621a0 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -343,6 +343,12 @@
#include "math/modff128.h"
#include "math/modff16.h"
#include "math/modfl.h"
+#include "math/nearbyint.h"
+#include "math/nearbyintbf16.h"
+#include "math/nearbyintf.h"
+#include "math/nearbyintf128.h"
+#include "math/nearbyintf16.h"
+#include "math/nearbyintl.h"
#include "math/nextafter.h"
#include "math/nextafterbf16.h"
#include "math/nextafterf.h"
@@ -380,6 +386,12 @@
#include "math/remquof128.h"
#include "math/remquof16.h"
#include "math/remquol.h"
+#include "math/rint.h"
+#include "math/rintbf16.h"
+#include "math/rintf.h"
+#include "math/rintf128.h"
+#include "math/rintf16.h"
+#include "math/rintl.h"
#include "math/rsqrtf.h"
#include "math/rsqrtf16.h"
#include "math/scalbln.h"
diff --git a/libc/shared/math/nearbyint.h b/libc/shared/math/nearbyint.h
new file mode 100644
index 0000000000000..e5439ecf24a79
--- /dev/null
+++ b/libc/shared/math/nearbyint.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyint 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_NEARBYINT_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINT_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyint.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyint;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINT_H
diff --git a/libc/shared/math/nearbyintbf16.h b/libc/shared/math/nearbyintbf16.h
new file mode 100644
index 0000000000000..f7b5eb47497c3
--- /dev/null
+++ b/libc/shared/math/nearbyintbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyintbf16 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_NEARBYINTBF16_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTBF16_H
diff --git a/libc/shared/math/nearbyintf.h b/libc/shared/math/nearbyintf.h
new file mode 100644
index 0000000000000..212a0700c56af
--- /dev/null
+++ b/libc/shared/math/nearbyintf.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyintf 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_NEARBYINTF_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTF_H
diff --git a/libc/shared/math/nearbyintf128.h b/libc/shared/math/nearbyintf128.h
new file mode 100644
index 0000000000000..824c5c98baf7d
--- /dev/null
+++ b/libc/shared/math/nearbyintf128.h
@@ -0,0 +1,29 @@
+//===-- Shared nearbyintf128 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_NEARBYINTF128_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTF128_H
diff --git a/libc/shared/math/nearbyintf16.h b/libc/shared/math/nearbyintf16.h
new file mode 100644
index 0000000000000..3a9eb50d1f8dd
--- /dev/null
+++ b/libc/shared/math/nearbyintf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nearbyintf16 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_NEARBYINTF16_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTF16_H
diff --git a/libc/shared/math/nearbyintl.h b/libc/shared/math/nearbyintl.h
new file mode 100644
index 0000000000000..bcfd937c24f94
--- /dev/null
+++ b/libc/shared/math/nearbyintl.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyintl 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_NEARBYINTL_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTL_H
diff --git a/libc/shared/math/rint.h b/libc/shared/math/rint.h
new file mode 100644
index 0000000000000..5908a9dbeb9e2
--- /dev/null
+++ b/libc/shared/math/rint.h
@@ -0,0 +1,23 @@
+//===-- Shared rint 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_RINT_H
+#define LLVM_LIBC_SHARED_MATH_RINT_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rint.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rint;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINT_H
diff --git a/libc/shared/math/rintbf16.h b/libc/shared/math/rintbf16.h
new file mode 100644
index 0000000000000..b22829f227692
--- /dev/null
+++ b/libc/shared/math/rintbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared rintbf16 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_RINTBF16_H
+#define LLVM_LIBC_SHARED_MATH_RINTBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTBF16_H
diff --git a/libc/shared/math/rintf.h b/libc/shared/math/rintf.h
new file mode 100644
index 0000000000000..7f829c3d75998
--- /dev/null
+++ b/libc/shared/math/rintf.h
@@ -0,0 +1,23 @@
+//===-- Shared rintf 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_RINTF_H
+#define LLVM_LIBC_SHARED_MATH_RINTF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTF_H
diff --git a/libc/shared/math/rintf128.h b/libc/shared/math/rintf128.h
new file mode 100644
index 0000000000000..13e2bf502c39e
--- /dev/null
+++ b/libc/shared/math/rintf128.h
@@ -0,0 +1,29 @@
+//===-- Shared rintf128 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_RINTF128_H
+#define LLVM_LIBC_SHARED_MATH_RINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTF128_H
diff --git a/libc/shared/math/rintf16.h b/libc/shared/math/rintf16.h
new file mode 100644
index 0000000000000..812b826ab746d
--- /dev/null
+++ b/libc/shared/math/rintf16.h
@@ -0,0 +1,29 @@
+//===-- Shared rintf16 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_RINTF16_H
+#define LLVM_LIBC_SHARED_MATH_RINTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTF16_H
diff --git a/libc/shared/math/rintl.h b/libc/shared/math/rintl.h
new file mode 100644
index 0000000000000..4e6de070b18c8
--- /dev/null
+++ b/libc/shared/math/rintl.h
@@ -0,0 +1,23 @@
+//===-- Shared rintl 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_RINTL_H
+#define LLVM_LIBC_SHARED_MATH_RINTL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 852b0b37cb844..a7d08c2d40cb5 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1954,6 +1954,63 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ nearbyint
+ HDRS
+ nearbyint.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nearbyintbf16
+ HDRS
+ nearbyintbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nearbyintf
+ HDRS
+ nearbyintf.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nearbyintf128
+ HDRS
+ nearbyintf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nearbyintf16
+ HDRS
+ nearbyintf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nearbyintl
+ HDRS
+ nearbyintl.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_header_library(
remainder
HDRS
@@ -2068,6 +2125,72 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ rint
+ HDRS
+ rint.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ rintbf16
+ HDRS
+ rintbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ rintf
+ HDRS
+ rintf.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ rintf128
+ HDRS
+ rintf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ rintf16
+ HDRS
+ rintf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ rintl
+ HDRS
+ rintl.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_header_library(
scalbln
HDRS
diff --git a/libc/src/__support/math/nearbyint.h b/libc/src/__support/math/nearbyint.h
new file mode 100644
index 0000000000000..762e88667cf59
--- /dev/null
+++ b/libc/src/__support/math/nearbyint.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for nearbyint ---------------------*- 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_NEARBYINT_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINT_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double nearbyint(double x) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINT_H
diff --git a/libc/src/__support/math/nearbyintbf16.h b/libc/src/__support/math/nearbyintbf16.h
new file mode 100644
index 0000000000000..81dd464b77125
--- /dev/null
+++ b/libc/src/__support/math/nearbyintbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nearbyintbf16 -----------------*- 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_NEARBYINTBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTBF16_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 nearbyintbf16(bfloat16 x) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTBF16_H
diff --git a/libc/src/__support/math/nearbyintf.h b/libc/src/__support/math/nearbyintf.h
new file mode 100644
index 0000000000000..2a96307aae92e
--- /dev/null
+++ b/libc/src/__support/math/nearbyintf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for nearbyintf --------------------*- 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_NEARBYINTF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float nearbyintf(float x) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF_H
diff --git a/libc/src/__support/math/nearbyintf128.h b/libc/src/__support/math/nearbyintf128.h
new file mode 100644
index 0000000000000..56d32cd61b5c5
--- /dev/null
+++ b/libc/src/__support/math/nearbyintf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for nearbyintf128 -----------------*- 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_NEARBYINTF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 nearbyintf128(float128 x) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF128_H
diff --git a/libc/src/__support/math/nearbyintf16.h b/libc/src/__support/math/nearbyintf16.h
new file mode 100644
index 0000000000000..d7e3fb4c6adef
--- /dev/null
+++ b/libc/src/__support/math/nearbyintf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for nearbyintf16 ------------------*- 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
+//
+//===-----------------------------------------------------...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/195577
More information about the libc-commits
mailing list