[libc-commits] [libc] [libc][math][c++23] Add {nearbyint, rint, lrint, llrint, lround, llround}bf16 math functions (PR #153882)
Krishna Pandey via libc-commits
libc-commits at lists.llvm.org
Fri Aug 15 14:41:20 PDT 2025
- Previous message: [libc-commits] [libc] [libc][math][c++23] Add {nearbyint, rint, lrint, llrint, lround, llround}bf16 math functions (PR #153882)
- Next message: [libc-commits] [libc] [libc][math][c++23] Add {nearbyint, rint, lrint, llrint, lround, llround}bf16 math functions (PR #153882)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
https://github.com/krishna2803 updated https://github.com/llvm/llvm-project/pull/153882
>From 6ca3fcfebd167254cdb0248d231c9b09b91f0ac6 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Fri, 15 Aug 2025 22:53:35 +0530
Subject: [PATCH 01/12] feat: implement
{nearbyint,rint,lrint,llrint,lround,llround}bf16 functions
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/src/math/generic/llrintbf16.cpp | 23 +++++++++++++++++++++++
libc/src/math/generic/llroundbf16.cpp | 21 +++++++++++++++++++++
libc/src/math/generic/lrintbf16.cpp | 22 ++++++++++++++++++++++
libc/src/math/generic/lroundbf16.cpp | 21 +++++++++++++++++++++
libc/src/math/generic/nearbyintbf16.cpp | 21 +++++++++++++++++++++
libc/src/math/generic/rintbf16.cpp | 21 +++++++++++++++++++++
libc/src/math/llrintbf16.h | 21 +++++++++++++++++++++
libc/src/math/llroundbf16.h | 21 +++++++++++++++++++++
libc/src/math/lrintbf16.h | 21 +++++++++++++++++++++
libc/src/math/lroundbf16.h | 21 +++++++++++++++++++++
libc/src/math/nearbyintbf16.h | 21 +++++++++++++++++++++
libc/src/math/rintbf16.h | 21 +++++++++++++++++++++
12 files changed, 255 insertions(+)
create mode 100644 libc/src/math/generic/llrintbf16.cpp
create mode 100644 libc/src/math/generic/llroundbf16.cpp
create mode 100644 libc/src/math/generic/lrintbf16.cpp
create mode 100644 libc/src/math/generic/lroundbf16.cpp
create mode 100644 libc/src/math/generic/nearbyintbf16.cpp
create mode 100644 libc/src/math/generic/rintbf16.cpp
create mode 100644 libc/src/math/llrintbf16.h
create mode 100644 libc/src/math/llroundbf16.h
create mode 100644 libc/src/math/lrintbf16.h
create mode 100644 libc/src/math/lroundbf16.h
create mode 100644 libc/src/math/nearbyintbf16.h
create mode 100644 libc/src/math/rintbf16.h
diff --git a/libc/src/math/generic/llrintbf16.cpp b/libc/src/math/generic/llrintbf16.cpp
new file mode 100644
index 0000000000000..acf4f8574356d
--- /dev/null
+++ b/libc/src/math/generic/llrintbf16.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of llrintbf16 function -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/llrintbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long long, llrintbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer_using_current_rounding_mode<bfloat16,
+ long long>(
+ x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/llroundbf16.cpp b/libc/src/math/generic/llroundbf16.cpp
new file mode 100644
index 0000000000000..ffbf34721f8ed
--- /dev/null
+++ b/libc/src/math/generic/llroundbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of llroundbf16 function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/llroundbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long long, llroundbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer<bfloat16, long long>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/lrintbf16.cpp b/libc/src/math/generic/lrintbf16.cpp
new file mode 100644
index 0000000000000..97e106c2b8759
--- /dev/null
+++ b/libc/src/math/generic/lrintbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of lrintbf16 function ------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/lrintbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long, lrintbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer_using_current_rounding_mode<bfloat16,
+ long>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/lroundbf16.cpp b/libc/src/math/generic/lroundbf16.cpp
new file mode 100644
index 0000000000000..227b07973ebc5
--- /dev/null
+++ b/libc/src/math/generic/lroundbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of lroundbf16 function -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/lroundbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long, lroundbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer<bfloat16, long>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nearbyintbf16.cpp b/libc/src/math/generic/nearbyintbf16.cpp
new file mode 100644
index 0000000000000..e9ca8a4e0b8a0
--- /dev/null
+++ b/libc/src/math/generic/nearbyintbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of nearbyintbf16 function --------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/nearbyintbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, nearbyintbf16, (bfloat16 x)) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rintbf16.cpp b/libc/src/math/generic/rintbf16.cpp
new file mode 100644
index 0000000000000..43b920883274d
--- /dev/null
+++ b/libc/src/math/generic/rintbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of rintbf16 function -------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/rintbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, rintbf16, (bfloat16 x)) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/llrintbf16.h b/libc/src/math/llrintbf16.h
new file mode 100644
index 0000000000000..23402a57806a9
--- /dev/null
+++ b/libc/src/math/llrintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for llrintbf16 --------------------*- 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_MATH_LLRINTBF16_H
+#define LLVM_LIBC_SRC_MATH_LLRINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long long llrintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LLRINTBF16_H
diff --git a/libc/src/math/llroundbf16.h b/libc/src/math/llroundbf16.h
new file mode 100644
index 0000000000000..69878e43c4460
--- /dev/null
+++ b/libc/src/math/llroundbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for llroundbf16 -------------------*- 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_MATH_LLROUNDBF16_H
+#define LLVM_LIBC_SRC_MATH_LLROUNDBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long long llroundbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LLROUNDBF16_H
diff --git a/libc/src/math/lrintbf16.h b/libc/src/math/lrintbf16.h
new file mode 100644
index 0000000000000..ec244728053a3
--- /dev/null
+++ b/libc/src/math/lrintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for lrintbf16 ---------------------*- 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_MATH_LRINTBF16_H
+#define LLVM_LIBC_SRC_MATH_LRINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long lrintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LRINTBF16_H
diff --git a/libc/src/math/lroundbf16.h b/libc/src/math/lroundbf16.h
new file mode 100644
index 0000000000000..c08db7a645b3e
--- /dev/null
+++ b/libc/src/math/lroundbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for lroundbf16 --------------------*- 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_MATH_LROUNDBF16_H
+#define LLVM_LIBC_SRC_MATH_LROUNDBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long lroundbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LROUNDBF16_H
diff --git a/libc/src/math/nearbyintbf16.h b/libc/src/math/nearbyintbf16.h
new file mode 100644
index 0000000000000..bc7eb3b6a315d
--- /dev/null
+++ b/libc/src/math/nearbyintbf16.h
@@ -0,0 +1,21 @@
+//===-- 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_MATH_NEARBYINTBF16_H
+#define LLVM_LIBC_SRC_MATH_NEARBYINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 nearbyintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_NEARBYINTBF16_H
diff --git a/libc/src/math/rintbf16.h b/libc/src/math/rintbf16.h
new file mode 100644
index 0000000000000..aae1541b583fa
--- /dev/null
+++ b/libc/src/math/rintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for rintbf16 ----------------------*- 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_MATH_RINTBF16_H
+#define LLVM_LIBC_SRC_MATH_RINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 rintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_RINTBF16_H
>From 1e4913978d4eeef1a15f219ec2fc68e6255bfd94 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Fri, 15 Aug 2025 22:53:52 +0530
Subject: [PATCH 02/12] chore: update CMakeLists.txt
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/src/math/CMakeLists.txt | 6 +++
libc/src/math/generic/CMakeLists.txt | 78 ++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 2cf5ae5eab726..9b9ea8fcfb1ef 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -387,24 +387,28 @@ add_math_entrypoint_object(llrintf)
add_math_entrypoint_object(llrintl)
add_math_entrypoint_object(llrintf16)
add_math_entrypoint_object(llrintf128)
+add_math_entrypoint_object(llrintbf16)
add_math_entrypoint_object(llround)
add_math_entrypoint_object(llroundf)
add_math_entrypoint_object(llroundl)
add_math_entrypoint_object(llroundf16)
add_math_entrypoint_object(llroundf128)
+add_math_entrypoint_object(llroundbf16)
add_math_entrypoint_object(lrint)
add_math_entrypoint_object(lrintf)
add_math_entrypoint_object(lrintl)
add_math_entrypoint_object(lrintf16)
add_math_entrypoint_object(lrintf128)
+add_math_entrypoint_object(lrintbf16)
add_math_entrypoint_object(lround)
add_math_entrypoint_object(lroundf)
add_math_entrypoint_object(lroundl)
add_math_entrypoint_object(lroundf16)
add_math_entrypoint_object(lroundf128)
+add_math_entrypoint_object(lroundbf16)
add_math_entrypoint_object(modf)
add_math_entrypoint_object(modff)
@@ -423,6 +427,7 @@ add_math_entrypoint_object(nearbyintf)
add_math_entrypoint_object(nearbyintl)
add_math_entrypoint_object(nearbyintf16)
add_math_entrypoint_object(nearbyintf128)
+add_math_entrypoint_object(nearbyintbf16)
add_math_entrypoint_object(nextafter)
add_math_entrypoint_object(nextafterf)
@@ -469,6 +474,7 @@ add_math_entrypoint_object(rintf)
add_math_entrypoint_object(rintl)
add_math_entrypoint_object(rintf16)
add_math_entrypoint_object(rintf128)
+add_math_entrypoint_object(rintbf16)
add_math_entrypoint_object(round)
add_math_entrypoint_object(roundf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 4351f1d7c8a9a..2423070a8383c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1024,6 +1024,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ lroundbf16
+ SRCS
+ lroundbf16.cpp
+ HDRS
+ ../lroundf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_entrypoint_object(
llround
SRCS
@@ -1076,6 +1089,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ llroundbf16
+ SRCS
+ llroundbf16.cpp
+ HDRS
+ ../llroundf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_entrypoint_object(
rint
SRCS
@@ -1136,6 +1162,21 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ rintbf16
+ SRCS
+ rintbf16.cpp
+ HDRS
+ ../rintbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
add_entrypoint_object(
lrint
SRCS
@@ -1188,6 +1229,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ lrintbf16
+ SRCS
+ lrintbf16.cpp
+ HDRS
+ ../lrintbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_entrypoint_object(
llrint
SRCS
@@ -1240,6 +1294,17 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ llrintbf16
+ SRCS
+ llrintbf16.cpp
+ HDRS
+ ../llrintbf16.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.nearest_integer_operations
+)
+
add_entrypoint_object(
nearbyint
SRCS
@@ -1292,6 +1357,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ nearbyintbf16
+ SRCS
+ nearbyintbf16.cpp
+ HDRS
+ ../nearbyintbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_entrypoint_object(
erff
SRCS
>From 5aa423e8e7cd2a4affd2824b2a887962338235dc Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Fri, 15 Aug 2025 23:49:43 +0530
Subject: [PATCH 03/12] chore: add smoke tests for
{nearbyint,rint,lrint,llrint,lround,llround}bf16 functions
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/test/src/math/smoke/CMakeLists.txt | 97 +++++++++++++++++++
libc/test/src/math/smoke/RoundToIntegerTest.h | 6 +-
libc/test/src/math/smoke/llrintbf16_test.cpp | 15 +++
libc/test/src/math/smoke/llroundbf16_test.cpp | 14 +++
libc/test/src/math/smoke/lrintbf16_test.cpp | 14 +++
libc/test/src/math/smoke/lroundbf16_test.cpp | 14 +++
.../src/math/smoke/nearbyintbf16_test.cpp | 14 +++
libc/test/src/math/smoke/rintbf16_test.cpp | 14 +++
8 files changed, 185 insertions(+), 3 deletions(-)
create mode 100644 libc/test/src/math/smoke/llrintbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/llroundbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/lrintbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/lroundbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/nearbyintbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/rintbf16_test.cpp
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index c3df8b1ff2c58..75f786cd44bb8 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -936,6 +936,23 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ lroundbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.lroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
llround_test
SUITE
@@ -1016,6 +1033,23 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ llroundbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ llroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.llroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
rint_test
SUITE
@@ -1086,6 +1120,21 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ rintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ rintbf16_test.cpp
+ HDRS
+ RIntTest.h
+ DEPENDS
+ libc.src.math.rintbf16
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
lrint_test
SUITE
@@ -1166,6 +1215,23 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ lrintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.lrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
llrint_test
SUITE
@@ -1246,6 +1312,23 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ llrintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ llrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.llrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
exp_test
SUITE
@@ -3527,6 +3610,20 @@ add_fp_unittest(
libc.src.math.nearbyintf128
)
+add_fp_unittest(
+ nearbyintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ nearbyintbf16_test.cpp
+ HDRS
+ NearbyIntTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.math.nearbyintbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
nextafter_test
SUITE
diff --git a/libc/test/src/math/smoke/RoundToIntegerTest.h b/libc/test/src/math/smoke/RoundToIntegerTest.h
index 2b460aef6ef32..6866e9109ca0a 100644
--- a/libc/test/src/math/smoke/RoundToIntegerTest.h
+++ b/libc/test/src/math/smoke/RoundToIntegerTest.h
@@ -97,8 +97,8 @@ class RoundToIntegerTestTemplate
test_one_input(func, F(-1.0), I(-1), false);
test_one_input(func, F(10.0), I(10), false);
test_one_input(func, F(-10.0), I(-10), false);
- test_one_input(func, F(1234.0), I(1234), false);
- test_one_input(func, F(-1234.0), I(-1234), false);
+ test_one_input(func, F(1232.0), I(1232), false);
+ test_one_input(func, F(-1232.0), I(-1232), false);
}
void testRoundNumbers(RoundToIntegerFunc func) {
@@ -124,7 +124,7 @@ class RoundToIntegerTestTemplate
continue;
// All subnormal numbers should round to zero.
if (TestModes) {
- if (x > 0) {
+ if (x > zero) {
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
test_one_input(func, x, I(1), false);
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
diff --git a/libc/test/src/math/smoke/llrintbf16_test.cpp b/libc/test/src/math/smoke/llrintbf16_test.cpp
new file mode 100644
index 0000000000000..e841e627e2634
--- /dev/null
+++ b/libc/test/src/math/smoke/llrintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for llrintbf16 ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long long,
+ LIBC_NAMESPACE::llrintbf16)
diff --git a/libc/test/src/math/smoke/llroundbf16_test.cpp b/libc/test/src/math/smoke/llroundbf16_test.cpp
new file mode 100644
index 0000000000000..c3b7ea43c3e8a
--- /dev/null
+++ b/libc/test/src/math/smoke/llroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for llroundbf16 -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long long, LIBC_NAMESPACE::llroundbf16)
diff --git a/libc/test/src/math/smoke/lrintbf16_test.cpp b/libc/test/src/math/smoke/lrintbf16_test.cpp
new file mode 100644
index 0000000000000..6b6bb1ae4de3b
--- /dev/null
+++ b/libc/test/src/math/smoke/lrintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for lrintbf16 -------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long, LIBC_NAMESPACE::lrintbf16)
diff --git a/libc/test/src/math/smoke/lroundbf16_test.cpp b/libc/test/src/math/smoke/lroundbf16_test.cpp
new file mode 100644
index 0000000000000..2f2b7b1a71b36
--- /dev/null
+++ b/libc/test/src/math/smoke/lroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for lroundbf16 ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long, LIBC_NAMESPACE::lroundbf16)
diff --git a/libc/test/src/math/smoke/nearbyintbf16_test.cpp b/libc/test/src/math/smoke/nearbyintbf16_test.cpp
new file mode 100644
index 0000000000000..2d64fc5a154ee
--- /dev/null
+++ b/libc/test/src/math/smoke/nearbyintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for nearbyintbf16 ---------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "NearbyIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/nearbyintbf16.h"
+
+LIST_NEARBYINT_TESTS(bfloat16, LIBC_NAMESPACE::nearbyintbf16)
diff --git a/libc/test/src/math/smoke/rintbf16_test.cpp b/libc/test/src/math/smoke/rintbf16_test.cpp
new file mode 100644
index 0000000000000..c78dcf6a31560
--- /dev/null
+++ b/libc/test/src/math/smoke/rintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for rintbf16 --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/rintbf16.h"
+
+LIST_RINT_TESTS(bfloat16, LIBC_NAMESPACE::rintbf16)
>From 292ce86e1d29c61abaa0707832fefe1fd2480674 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Fri, 15 Aug 2025 23:50:52 +0530
Subject: [PATCH 04/12] feat: add static_cast<T> support for integer Ts from
bfloat16
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/src/__support/FPUtil/bfloat16.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index 3fab2b80317de..ea269a45767ee 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -61,6 +61,11 @@ struct BFloat16 {
return cpp::bit_cast<float>(x_bits);
}
+ template <typename T, cpp::enable_if_t<std::is_integral_v<T>, int> = 0>
+ LIBC_INLINE constexpr explicit operator T() const {
+ return static_cast<T>(static_cast<float>(*this));
+ }
+
LIBC_INLINE bool operator==(BFloat16 other) const {
return fputil::equals(*this, other);
}
>From 8669fd89685fe45bbc4c67f62f6ebb381de8d01a Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 00:16:16 +0530
Subject: [PATCH 05/12] chore: update entrypoints
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/config/baremetal/aarch64/entrypoints.txt | 6 ++++++
libc/config/baremetal/arm/entrypoints.txt | 6 ++++++
libc/config/baremetal/riscv/entrypoints.txt | 6 ++++++
libc/config/darwin/aarch64/entrypoints.txt | 6 ++++++
libc/config/darwin/x86_64/entrypoints.txt | 7 ++++++-
libc/config/gpu/amdgpu/entrypoints.txt | 6 ++++++
libc/config/gpu/nvptx/entrypoints.txt | 6 ++++++
libc/config/linux/aarch64/entrypoints.txt | 6 ++++++
libc/config/linux/arm/entrypoints.txt | 6 ++++++
libc/config/linux/riscv/entrypoints.txt | 6 ++++++
libc/config/linux/x86_64/entrypoints.txt | 6 ++++++
libc/config/windows/entrypoints.txt | 6 ++++++
12 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 007d64d3fcd7c..ae38ea6ff058e 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -782,6 +782,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 6c1f52a8f1ca2..55f6966a26767 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -785,6 +785,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index d1412762333de..ee7f89ac7f8e9 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -785,6 +785,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 57c09f0725048..7f079840b8e86 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -615,6 +615,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 9b207fd734e99..311cec3976f8c 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -258,7 +258,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
-
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 8981190cfe1bc..2cac0d99f57be 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -641,6 +641,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index dc23742652783..72a4f89fdd4cb 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -642,6 +642,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 5f687525271ee..c854e26edc4da 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -869,6 +869,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 47689a2234aca..ed4f644fc3647 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -485,6 +485,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index b9efadc7deef2..6a78eba2bd0c4 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -888,6 +888,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 458cb5999e403..535996da9c072 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -920,6 +920,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 00104a31af44e..c522d3dcd5fa1 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -331,6 +331,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.llrintbf16
+ libc.src.math.llroundbf16
+ libc.src.math.lrintbf16
+ libc.src.math.lroundbf16
+ libc.src.math.nearbyintbf16
+ libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.truncbf16
>From 69418efc5471d34c75608e2770bc3cef0771e2f2 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 00:31:22 +0530
Subject: [PATCH 06/12] chore: add general tests for
{nearbyint,rint,lrint,llrint,lround,llround}bf16 functions
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/test/src/math/CMakeLists.txt | 106 ++++++++++++++++++++++
libc/test/src/math/llrintbf16_test.cpp | 15 +++
libc/test/src/math/llroundbf16_test.cpp | 14 +++
libc/test/src/math/lrintbf16_test.cpp | 14 +++
libc/test/src/math/lroundbf16_test.cpp | 14 +++
libc/test/src/math/nearbyintbf16_test.cpp | 15 +++
libc/test/src/math/rintbf16_test.cpp | 14 +++
7 files changed, 192 insertions(+)
create mode 100644 libc/test/src/math/llrintbf16_test.cpp
create mode 100644 libc/test/src/math/llroundbf16_test.cpp
create mode 100644 libc/test/src/math/lrintbf16_test.cpp
create mode 100644 libc/test/src/math/lroundbf16_test.cpp
create mode 100644 libc/test/src/math/nearbyintbf16_test.cpp
create mode 100644 libc/test/src/math/rintbf16_test.cpp
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 85dddfb88d7e6..d838d966e35ff 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -668,6 +668,25 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ lroundbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.errno.errno
+ libc.src.math.lroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
llround_test
NEED_MPFR
@@ -740,6 +759,25 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ llroundbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ llroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.errno.errno
+ libc.src.math.llroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
nearbyint_test
NEED_MPFR
@@ -800,6 +838,22 @@ add_fp_unittest(
libc.src.__support.CPP.array
)
+add_fp_unittest(
+ nearbyintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ nearbyintbf16_test.cpp
+ HDRS
+ NearbyIntTest.h
+ DEPENDS
+ libc.src.math.nearbyintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.CPP.array
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
rint_test
NEED_MPFR
@@ -868,6 +922,24 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ rintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ rintbf16_test.cpp
+ HDRS
+ RIntTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.math.rintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
lrint_test
NEED_MPFR
@@ -932,6 +1004,23 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ lrintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.math.lrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
llrint_test
NEED_MPFR
@@ -996,6 +1085,23 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ llrintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ llrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.math.llrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
exp_test
NEED_MPFR
diff --git a/libc/test/src/math/llrintbf16_test.cpp b/libc/test/src/math/llrintbf16_test.cpp
new file mode 100644
index 0000000000000..e841e627e2634
--- /dev/null
+++ b/libc/test/src/math/llrintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for llrintbf16 ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long long,
+ LIBC_NAMESPACE::llrintbf16)
diff --git a/libc/test/src/math/llroundbf16_test.cpp b/libc/test/src/math/llroundbf16_test.cpp
new file mode 100644
index 0000000000000..c3b7ea43c3e8a
--- /dev/null
+++ b/libc/test/src/math/llroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for llroundbf16 -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long long, LIBC_NAMESPACE::llroundbf16)
diff --git a/libc/test/src/math/lrintbf16_test.cpp b/libc/test/src/math/lrintbf16_test.cpp
new file mode 100644
index 0000000000000..6b6bb1ae4de3b
--- /dev/null
+++ b/libc/test/src/math/lrintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for lrintbf16 -------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long, LIBC_NAMESPACE::lrintbf16)
diff --git a/libc/test/src/math/lroundbf16_test.cpp b/libc/test/src/math/lroundbf16_test.cpp
new file mode 100644
index 0000000000000..2f2b7b1a71b36
--- /dev/null
+++ b/libc/test/src/math/lroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for lroundbf16 ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long, LIBC_NAMESPACE::lroundbf16)
diff --git a/libc/test/src/math/nearbyintbf16_test.cpp b/libc/test/src/math/nearbyintbf16_test.cpp
new file mode 100644
index 0000000000000..921191fbacbf0
--- /dev/null
+++ b/libc/test/src/math/nearbyintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for nearbyintbf16 ---------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "NearbyIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/nearbyintbf16.h"
+
+LIST_NEARBYINT_TESTS(bfloat16, LIBC_NAMESPACE::nearbyintbf16)
diff --git a/libc/test/src/math/rintbf16_test.cpp b/libc/test/src/math/rintbf16_test.cpp
new file mode 100644
index 0000000000000..c78dcf6a31560
--- /dev/null
+++ b/libc/test/src/math/rintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for rintbf16 --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "RIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/rintbf16.h"
+
+LIST_RINT_TESTS(bfloat16, LIBC_NAMESPACE::rintbf16)
>From 70e7744a63199be8e1b5fef6096a06506f9cbae6 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 00:32:02 +0530
Subject: [PATCH 07/12] chore: update MPFRUtils and tests for bfloat16 rounding
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/test/src/math/RoundToIntegerTest.h | 4 ++--
libc/utils/MPFRWrapper/MPFRUtils.cpp | 6 ++++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h
index 6af9cfea0e0a5..e5e93869a3235 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -127,8 +127,8 @@ class RoundToIntegerTestTemplate
test_one_input(func, FloatType(-1.0), IntType(-1), false);
test_one_input(func, FloatType(10.0), IntType(10), false);
test_one_input(func, FloatType(-10.0), IntType(-10), false);
- test_one_input(func, FloatType(1234.0), IntType(1234), false);
- test_one_input(func, FloatType(-1234.0), IntType(-1234), false);
+ test_one_input(func, FloatType(1232.0), IntType(1232), false);
+ test_one_input(func, FloatType(-1232.0), IntType(-1232), false);
// The rest of this function compares with an equivalent MPFR function
// which rounds floating point numbers to long values. There is no MPFR
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 57e818ca3d9c3..79053028716c1 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -753,6 +753,8 @@ template bool round_to_long<float16>(float16, long &);
template bool round_to_long<float128>(float128, long &);
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool round_to_long<bfloat16>(bfloat16, long &);
+
template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
MPFRNumber mpfr(x);
return mpfr.round_to_long(get_mpfr_rounding_mode(mode), result);
@@ -770,6 +772,8 @@ template bool round_to_long<float16>(float16, RoundingMode, long &);
template bool round_to_long<float128>(float128, RoundingMode, long &);
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool round_to_long<bfloat16>(bfloat16, RoundingMode, long &);
+
template <typename T> T round(T x, RoundingMode mode) {
MPFRNumber mpfr(x);
MPFRNumber result = mpfr.rint(get_mpfr_rounding_mode(mode));
@@ -788,6 +792,8 @@ template float16 round<float16>(float16, RoundingMode);
template float128 round<float128>(float128, RoundingMode);
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bfloat16 round<bfloat16>(bfloat16, RoundingMode);
+
} // namespace mpfr
} // namespace testing
} // namespace LIBC_NAMESPACE_DECL
>From a59c06c013bb6adab025ae973f98f560a1f4ca0e Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 00:40:58 +0530
Subject: [PATCH 08/12] docs: add
{nearbyint,rint,lrint,llrint,lround,llround}bf16 functions
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/docs/headers/math/index.rst | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index add34d0e877fd..bd3ae3023f372 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -199,21 +199,21 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.10 | F.10.3.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llrint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.5 | F.10.6.5 |
+| llrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llround | |check| | |check| | |check| | |check| | |check| | | 7.12.9.7 | F.10.6.7 |
+| llround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
+| logb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lrint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.5 | F.10.6.5 |
+| lrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lround | |check| | |check| | |check| | |check| | |check| | | 7.12.9.7 | F.10.6.7 |
+| lround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| modf | |check| | |check| | |check| | |check| | |check| | | 7.12.6.18 | F.10.3.18 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| nan | |check| | |check| | |check| | |check| | |check| | | 7.12.11.2 | F.10.8.2 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nearbyint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.3 | F.10.6.3 |
+| nearbyint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.3 | F.10.6.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| nextafter | |check| | |check| | |check| | |check| | |check| | | 7.12.11.3 | F.10.8.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
>From 35d7626313dd9e0483f15645c9ce0614a4bb7c9b Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 03:03:20 +0530
Subject: [PATCH 09/12] style: clang-format
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/src/math/generic/llrintbf16.cpp | 2 +-
libc/src/math/generic/llroundbf16.cpp | 2 +-
libc/src/math/generic/lrintbf16.cpp | 2 +-
libc/src/math/generic/lroundbf16.cpp | 2 +-
libc/src/math/generic/nearbyintbf16.cpp | 2 +-
libc/src/math/generic/rintbf16.cpp | 2 +-
libc/test/src/math/lrintbf16_test.cpp | 3 ++-
libc/test/src/math/nearbyintbf16_test.cpp | 1 -
libc/test/src/math/smoke/lrintbf16_test.cpp | 3 ++-
9 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/libc/src/math/generic/llrintbf16.cpp b/libc/src/math/generic/llrintbf16.cpp
index acf4f8574356d..ec85454d788ff 100644
--- a/libc/src/math/generic/llrintbf16.cpp
+++ b/libc/src/math/generic/llrintbf16.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/llrintbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
diff --git a/libc/src/math/generic/llroundbf16.cpp b/libc/src/math/generic/llroundbf16.cpp
index ffbf34721f8ed..2497b6b4a7df3 100644
--- a/libc/src/math/generic/llroundbf16.cpp
+++ b/libc/src/math/generic/llroundbf16.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/llroundbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
diff --git a/libc/src/math/generic/lrintbf16.cpp b/libc/src/math/generic/lrintbf16.cpp
index 97e106c2b8759..4b378909413d3 100644
--- a/libc/src/math/generic/lrintbf16.cpp
+++ b/libc/src/math/generic/lrintbf16.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/lrintbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
diff --git a/libc/src/math/generic/lroundbf16.cpp b/libc/src/math/generic/lroundbf16.cpp
index 227b07973ebc5..89095d1786f63 100644
--- a/libc/src/math/generic/lroundbf16.cpp
+++ b/libc/src/math/generic/lroundbf16.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/lroundbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
diff --git a/libc/src/math/generic/nearbyintbf16.cpp b/libc/src/math/generic/nearbyintbf16.cpp
index e9ca8a4e0b8a0..a6391995963ff 100644
--- a/libc/src/math/generic/nearbyintbf16.cpp
+++ b/libc/src/math/generic/nearbyintbf16.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/nearbyintbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
diff --git a/libc/src/math/generic/rintbf16.cpp b/libc/src/math/generic/rintbf16.cpp
index 43b920883274d..2ffe16a716205 100644
--- a/libc/src/math/generic/rintbf16.cpp
+++ b/libc/src/math/generic/rintbf16.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/rintbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
diff --git a/libc/test/src/math/lrintbf16_test.cpp b/libc/test/src/math/lrintbf16_test.cpp
index 6b6bb1ae4de3b..65a5633b81723 100644
--- a/libc/test/src/math/lrintbf16_test.cpp
+++ b/libc/test/src/math/lrintbf16_test.cpp
@@ -11,4 +11,5 @@
#include "src/__support/FPUtil/bfloat16.h"
#include "src/math/lrintbf16.h"
-LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long, LIBC_NAMESPACE::lrintbf16)
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long,
+ LIBC_NAMESPACE::lrintbf16)
diff --git a/libc/test/src/math/nearbyintbf16_test.cpp b/libc/test/src/math/nearbyintbf16_test.cpp
index 921191fbacbf0..2d64fc5a154ee 100644
--- a/libc/test/src/math/nearbyintbf16_test.cpp
+++ b/libc/test/src/math/nearbyintbf16_test.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-
#include "NearbyIntTest.h"
#include "src/__support/FPUtil/bfloat16.h"
diff --git a/libc/test/src/math/smoke/lrintbf16_test.cpp b/libc/test/src/math/smoke/lrintbf16_test.cpp
index 6b6bb1ae4de3b..65a5633b81723 100644
--- a/libc/test/src/math/smoke/lrintbf16_test.cpp
+++ b/libc/test/src/math/smoke/lrintbf16_test.cpp
@@ -11,4 +11,5 @@
#include "src/__support/FPUtil/bfloat16.h"
#include "src/math/lrintbf16.h"
-LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long, LIBC_NAMESPACE::lrintbf16)
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long,
+ LIBC_NAMESPACE::lrintbf16)
>From ab1bbdeca09c90711fbcaefdded242b1f88b26b0 Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 03:03:34 +0530
Subject: [PATCH 10/12] docs: fix incorrect check
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/docs/headers/math/index.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index bd3ae3023f372..92e1c0ba38639 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -203,7 +203,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.17 | F.10.3.17 |
+| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
@@ -227,7 +227,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| remquo | |check| | |check| | |check| | |check| | |check| | | 7.12.10.3 | F.10.7.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| rint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.4 | F.10.6.4 |
+| rint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.4 | F.10.6.4 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| round | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.6 | F.10.6.6 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
>From 3bca59b923d3cb606682fa64c3d170623761255c Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 03:04:24 +0530
Subject: [PATCH 11/12] fix: typo std -> cpp
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/src/__support/FPUtil/bfloat16.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index ea269a45767ee..f367ed7074f1b 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -61,7 +61,7 @@ struct BFloat16 {
return cpp::bit_cast<float>(x_bits);
}
- template <typename T, cpp::enable_if_t<std::is_integral_v<T>, int> = 0>
+ template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
LIBC_INLINE constexpr explicit operator T() const {
return static_cast<T>(static_cast<float>(*this));
}
>From a73116689cc457b2a60f56557bad8c3d85e39fec Mon Sep 17 00:00:00 2001
From: Krishna Pandey <kpandey81930 at gmail.com>
Date: Sat, 16 Aug 2025 03:08:54 +0530
Subject: [PATCH 12/12] docs: add spacing
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
---
libc/docs/headers/math/index.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 92e1c0ba38639..3fc69aeda24c8 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -203,7 +203,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
+| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
- Previous message: [libc-commits] [libc] [libc][math][c++23] Add {nearbyint, rint, lrint, llrint, lround, llround}bf16 math functions (PR #153882)
- Next message: [libc-commits] [libc] [libc][math][c++23] Add {nearbyint, rint, lrint, llrint, lround, llround}bf16 math functions (PR #153882)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the libc-commits
mailing list