[libc-commits] [libc] [llvm] [libc][math] Implement isnanbf16 function (PR #238777)
Vaibhav Agrawal via libc-commits
libc-commits at lists.llvm.org
Mon Nov 9 12:59:50 PST 2026
https://github.com/competitive-programmer04 updated https://github.com/llvm/llvm-project/pull/238777
>From 9d2247311fa92f1b7ce42472a96501d0402e1db6 Mon Sep 17 00:00:00 2001
From: competitive-programmer04 <coder8809 at gmail.com>
Date: Wed, 4 Nov 2026 18:18:52 +0530
Subject: [PATCH 1/2] [libc][math] Implement isnanbf16 function
Add support for the isnanbf16 function for bfloat16 floating point type.
Uses fputil::FPBits<bfloat16>::is_nan() for the underlying implementation.
Includes unit smoke tests covering special constants (NaNs, infinities, zeros, subnormals) and rounded numbers.
---
libc/config/baremetal/aarch64/entrypoints.txt | 1 +
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/hexagon/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/darwin/aarch64/entrypoints.txt | 1 +
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/freebsd/x86_64/entrypoints.txt | 1 +
libc/config/gpu/amdgpu/entrypoints.txt | 1 +
libc/config/gpu/nvptx/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
libc/shared/math.h | 1 +
libc/shared/math/isnanbf16.h | 21 +++++++++++++++
libc/src/__support/math/CMakeLists.txt | 10 +++++++
libc/src/__support/math/isnanbf16.h | 27 +++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 10 +++++++
libc/src/math/generic/isnanbf16.cpp | 15 +++++++++++
libc/src/math/isnanbf16.h | 22 +++++++++++++++
libc/test/shared/CMakeLists.txt | 1 +
.../shared/shared_math_constexpr_test.cpp | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
libc/test/src/math/smoke/CMakeLists.txt | 13 +++++++++
libc/test/src/math/smoke/isnanbf16_test.cpp | 15 +++++++++++
.../llvm-project-overlay/libc/BUILD.bazel | 17 ++++++++++++
.../libc/test/src/math/smoke/BUILD.bazel | 8 ++++++
29 files changed, 177 insertions(+)
create mode 100644 libc/shared/math/isnanbf16.h
create mode 100644 libc/src/__support/math/isnanbf16.h
create mode 100644 libc/src/math/generic/isnanbf16.cpp
create mode 100644 libc/src/math/isnanbf16.h
create mode 100644 libc/test/src/math/smoke/isnanbf16_test.cpp
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 5cec9bf6308c52..1e4731dfdb0278 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -732,6 +732,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 8e9d282af024fd..a31294bac24069 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -744,6 +744,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/baremetal/hexagon/entrypoints.txt b/libc/config/baremetal/hexagon/entrypoints.txt
index f10de569db06f6..1f769f319af47d 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -683,6 +683,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 591ccdc0046126..64c7d23eaa1c18 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -735,6 +735,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 795e3a1d35b0a5..e729dd6fe8e0f4 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -554,6 +554,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index a8d9027f0646d1..e078593a67facf 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -336,6 +336,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index fc253220765666..f5d42e586e5b9b 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -628,6 +628,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 925a8edcfd7a43..b9faaf27d8f2f8 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -669,6 +669,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index be18714d41913f..fa28413072af96 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -667,6 +667,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 3d8281a3014db4..0e430dbb694210 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -983,6 +983,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index d0455d605f0e3f..b3e80fdad3fe1e 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -730,6 +730,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a4846ba0712659..4b4c9217cc4695 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1057,6 +1057,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index d97f363a06b9ae..0df7223dfe9121 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1079,6 +1079,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 8e5e6b748b3ef7..f376102a370df5 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -436,6 +436,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/shared/math.h b/libc/shared/math.h
index f7616676b27c08..13a4cbf9c0a62a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -311,6 +311,7 @@
#include "math/iscanonicall.h"
// TODO: isnan is a macro in <math.h>
// #include "math/isnan.h"
+#include "math/isnanbf16.h"
#include "math/isnanf.h"
#include "math/isnanf128.h"
#include "math/isnanf16.h"
diff --git a/libc/shared/math/isnanbf16.h b/libc/shared/math/isnanbf16.h
new file mode 100644
index 00000000000000..528a45f86b880b
--- /dev/null
+++ b/libc/shared/math/isnanbf16.h
@@ -0,0 +1,21 @@
+//===-- Shared isnanbf16 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_ISNANBF16_H
+#define LLVM_LIBC_SHARED_MATH_ISNANBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnanbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+using math::isnanbf16;
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+#endif // LLVM_LIBC_SHARED_MATH_ISNANBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index a4595642edafbf..81266ea28e8f97 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1896,6 +1896,16 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ isnanbf16
+ HDRS
+ isnanbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.macros.config
+)
+
add_header_library(
issignaling
HDRS
diff --git a/libc/src/__support/math/isnanbf16.h b/libc/src/__support/math/isnanbf16.h
new file mode 100644
index 00000000000000..48e6af724f9ba2
--- /dev/null
+++ b/libc/src/__support/math/isnanbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for isnanbf16 ----------------------*- 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_ISNANBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNANBF16_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int isnanbf16(bfloat16 x) {
+ return fputil::FPBits<bfloat16>(x).is_nan();
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNANBF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 2a75aba26a2c7b..f00e80c5ed2b81 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -388,6 +388,7 @@ add_math_entrypoint_object(ilogbbf16)
add_math_entrypoint_object(isnan)
add_math_entrypoint_object(isnanf)
add_math_entrypoint_object(isnanf16)
+add_math_entrypoint_object(isnanbf16)
add_math_entrypoint_object(isnanf128)
add_math_entrypoint_object(isnanf80)
add_math_entrypoint_object(isnanl)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index e7117cd2d3ee57..44c347c7c93077 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3319,6 +3319,16 @@ add_entrypoint_object(
libc.src.__support.math.isnanf16
)
+add_entrypoint_object(
+ isnanbf16
+ SRCS
+ isnanbf16.cpp
+ HDRS
+ ../isnanbf16.h
+ DEPENDS
+ libc.src.__support.math.isnanbf16
+)
+
add_entrypoint_object(
nan
SRCS
diff --git a/libc/src/math/generic/isnanbf16.cpp b/libc/src/math/generic/isnanbf16.cpp
new file mode 100644
index 00000000000000..80c99e42a23440
--- /dev/null
+++ b/libc/src/math/generic/isnanbf16.cpp
@@ -0,0 +1,15 @@
+//===-- Implementation of isnanbf16 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/isnanbf16.h"
+#include "src/__support/math/isnanbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(int, isnanbf16, (bfloat16 x)) { return math::isnanbf16(x); }
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/isnanbf16.h b/libc/src/math/isnanbf16.h
new file mode 100644
index 00000000000000..7fe6afe38abad0
--- /dev/null
+++ b/libc/src/math/isnanbf16.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for isnanbf16 ----------------------*- 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_ISNANBF16_H
+#define LLVM_LIBC_SRC_MATH_ISNANBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int isnanbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISNANBF16_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index e71040c591b56a..b9ae98adf3ec82 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -328,6 +328,7 @@ else()
libc.src.__support.math.isnanf128
libc.src.__support.math.isnanf80
libc.src.__support.math.isnanf16
+ libc.src.__support.math.isnanbf16
libc.src.__support.math.isnanl
libc.src.__support.math.issignaling
libc.src.__support.math.issignalingbf16
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 3b162ca663e7d4..13caf0f7916acd 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -292,6 +292,7 @@ static_assert(0.0f16 == LIBC_NAMESPACE::shared::nextafterf16(0.0f16, 0.0f16));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::rintf16(0.0f16));
static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf16(0.0f16));
static_assert(0 == LIBC_NAMESPACE::shared::isnanf16(0.0f16));
+static_assert(0 == LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.016)));
static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf16(0.0f16));
static_assert(1 == [] {
const char arg{};
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 27d4a3b5fd36a1..5bea3571f94dd8 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -165,6 +165,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::rintf16(0.0f16));
EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicalf16(0.0f16));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanf16(0.0f16));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.016)));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingf16(0.0f16));
EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf16("")).is_nan());
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::roundf16(0.0f16));
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index d8fc62a1143087..d7d7135be07081 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -2327,6 +2327,19 @@ add_fp_unittest(
libc.src.math.isnanf16
)
+add_fp_unittest(
+ isnanbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ isnanbf16_test.cpp
+ HDRS
+ IsNanTest.h
+ DEPENDS
+ libc.src.math.isnanbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
llogb_test
SUITE
diff --git a/libc/test/src/math/smoke/isnanbf16_test.cpp b/libc/test/src/math/smoke/isnanbf16_test.cpp
new file mode 100644
index 00000000000000..bdd553b3112c9a
--- /dev/null
+++ b/libc/test/src/math/smoke/isnanbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for isnanbf16
+//--------------------------------------------===//
+//
+// 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 "IsNanTest.h"
+#include "src/__support/FPUtil/bfloat16.h"
+
+#include "src/math/isnanbf16.h"
+
+LIST_ISNAN_TESTS(Isnanbf16, bfloat16, LIBC_NAMESPACE::isnanbf16)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 4c001a29091221..beb217b4952400 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -8455,6 +8455,16 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_isnanbf16",
+ hdrs = ["src/__support/math/isnanbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_fp_bits",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_issignaling",
hdrs = ["src/__support/math/issignaling.h"],
@@ -13912,6 +13922,13 @@ libc_math_function(
],
)
+libc_math_function(
+ name = "isnanbf16",
+ additional_deps = [
+ ":__support_math_isnanbf16",
+ ],
+)
+
libc_math_function(
name = "issignaling",
additional_deps = [
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index a0e51425a7f9a3..cf7935e04eb0a1 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1629,6 +1629,14 @@ math_test(
hdrs = ["IsNanTest.h"],
)
+math_test(
+ name = "isnanbf16",
+ hdrs = ["IsNanTest.h"],
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_test(
name = "llogbf16",
hdrs = ["ILogbTest.h"],
>From f910050032ef89dc2c7beb4affe13d4ad995cab6 Mon Sep 17 00:00:00 2001
From: competitive-programmer04 <coder8809 at gmail.com>
Date: Tue, 10 Nov 2026 01:57:06 +0530
Subject: [PATCH 2/2] [libc][math] checking for ninja
---
libc/config/baremetal/aarch64/entrypoints.txt | 2 +-
libc/config/baremetal/arm/entrypoints.txt | 2 +-
libc/config/baremetal/hexagon/entrypoints.txt | 2 +-
libc/config/baremetal/riscv/entrypoints.txt | 2 +-
libc/config/darwin/aarch64/entrypoints.txt | 2 +-
libc/config/gpu/amdgpu/entrypoints.txt | 2 +-
libc/config/gpu/nvptx/entrypoints.txt | 2 +-
libc/config/linux/aarch64/entrypoints.txt | 2 +-
libc/config/linux/riscv/entrypoints.txt | 2 +-
libc/config/linux/x86_64/entrypoints.txt | 2 +-
libc/shared/math/isnanbf16.h | 9 +++++++--
libc/src/__support/math/isnanbf16.h | 8 ++++++--
libc/src/math/generic/isnanbf16.cpp | 8 ++++++--
libc/src/math/isnanbf16.h | 8 ++++++--
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_constexpr_test.cpp | 2 +-
libc/test/shared/shared_math_test.cpp | 2 +-
libc/test/src/math/smoke/isnanbf16_test.cpp | 8 ++++++--
18 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 1e4731dfdb0278..06f3f371988f6d 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -732,7 +732,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -875,6 +874,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index a31294bac24069..7933cd5cb350a9 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -744,7 +744,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -886,6 +885,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/baremetal/hexagon/entrypoints.txt b/libc/config/baremetal/hexagon/entrypoints.txt
index 1f769f319af47d..4c06b3701c38ca 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -683,7 +683,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -875,6 +874,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 64c7d23eaa1c18..47f2e0a1d8f99e 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -735,7 +735,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -878,6 +877,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index e729dd6fe8e0f4..cff61bd191157a 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -554,7 +554,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -697,6 +696,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index b9faaf27d8f2f8..273e6c0e2f8c8d 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -669,7 +669,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -762,6 +761,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index fa28413072af96..f1314f6290f945 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -667,7 +667,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -778,6 +777,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 0e430dbb694210..3dd59a94d37e3c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -983,7 +983,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -1123,6 +1122,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 4b4c9217cc4695..7a5496ad4b632f 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1057,7 +1057,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -1203,6 +1202,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0df7223dfe9121..f5523f90d845fb 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1079,7 +1079,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.isnanf16
- libc.src.math.isnanbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.lgammaf16
@@ -1225,6 +1224,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
+ libc.src.math.isnanbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
diff --git a/libc/shared/math/isnanbf16.h b/libc/shared/math/isnanbf16.h
index 528a45f86b880b..52bf0138daa261 100644
--- a/libc/shared/math/isnanbf16.h
+++ b/libc/shared/math/isnanbf16.h
@@ -1,11 +1,16 @@
-//===-- Shared isnanbf16 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
//
//===----------------------------------------------------------------------===//
+///
+/// \brief
+/// This file will be used for shared_math_test.cpp and
+/// shared_math_constexpr_test.cpp
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SHARED_MATH_ISNANBF16_H
#define LLVM_LIBC_SHARED_MATH_ISNANBF16_H
diff --git a/libc/src/__support/math/isnanbf16.h b/libc/src/__support/math/isnanbf16.h
index 48e6af724f9ba2..ba01123f045c51 100644
--- a/libc/src/__support/math/isnanbf16.h
+++ b/libc/src/__support/math/isnanbf16.h
@@ -1,11 +1,15 @@
-//===-- Implementation header for isnanbf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//
+///
+/// \brief
+/// This file implements the isnanbf16 function using FPBits.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ISNANBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNANBF16_H
diff --git a/libc/src/math/generic/isnanbf16.cpp b/libc/src/math/generic/isnanbf16.cpp
index 80c99e42a23440..36da87458c13d0 100644
--- a/libc/src/math/generic/isnanbf16.cpp
+++ b/libc/src/math/generic/isnanbf16.cpp
@@ -1,11 +1,15 @@
-//===-- Implementation of isnanbf16 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
//
//===----------------------------------------------------------------------===//
+///
+/// \brief
+/// This file implements the entrypoint for isnanbf16.
+///
+//===----------------------------------------------------------------------===//
#include "src/math/isnanbf16.h"
#include "src/__support/math/isnanbf16.h"
diff --git a/libc/src/math/isnanbf16.h b/libc/src/math/isnanbf16.h
index 7fe6afe38abad0..f0a1339ea73c39 100644
--- a/libc/src/math/isnanbf16.h
+++ b/libc/src/math/isnanbf16.h
@@ -1,11 +1,15 @@
-//===-- Implementation header for isnanbf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//
+///
+/// \brief
+/// This file declares the isnanbf16 function.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_MATH_ISNANBF16_H
#define LLVM_LIBC_SRC_MATH_ISNANBF16_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index b9ae98adf3ec82..6c084ce5fa21a6 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -733,6 +733,7 @@ else()
libc.src.__support.math.isnanf128
libc.src.__support.math.isnanf80
libc.src.__support.math.isnanf16
+ libc.src.__support.math.isnanbf16
libc.src.__support.math.isnanl
libc.src.__support.math.issignaling
libc.src.__support.math.issignalingbf16
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 13caf0f7916acd..18a257a7dda5d9 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -292,7 +292,6 @@ static_assert(0.0f16 == LIBC_NAMESPACE::shared::nextafterf16(0.0f16, 0.0f16));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::rintf16(0.0f16));
static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf16(0.0f16));
static_assert(0 == LIBC_NAMESPACE::shared::isnanf16(0.0f16));
-static_assert(0 == LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.016)));
static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf16(0.0f16));
static_assert(1 == [] {
const char arg{};
@@ -732,6 +731,7 @@ static_assert(bfloat16(0.0) ==
bfloat16(0.0)));
static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::rintbf16(bfloat16(0.0)));
static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalbf16(bfloat16(0.0)));
+static_assert(0 == LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.0)));
static_assert(0 == LIBC_NAMESPACE::shared::issignalingbf16(bfloat16(0.0)));
static_assert(bfloat16(1) == [] {
const char arg{};
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 5bea3571f94dd8..f5c9e88d6cced3 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -165,7 +165,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::rintf16(0.0f16));
EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicalf16(0.0f16));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanf16(0.0f16));
- EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.016)));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingf16(0.0f16));
EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf16("")).is_nan());
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::roundf16(0.0f16));
@@ -956,6 +955,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
LIBC_NAMESPACE::shared::nearbyintbf16(bfloat16(0.0)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::rintbf16(bfloat16(0.0)));
EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicalbf16(bfloat16(0.0)));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.0)));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingbf16(bfloat16(0.0)));
EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanbf16("")).is_nan());
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::roundbf16(bfloat16(0.0)));
diff --git a/libc/test/src/math/smoke/isnanbf16_test.cpp b/libc/test/src/math/smoke/isnanbf16_test.cpp
index bdd553b3112c9a..827b28753347b1 100644
--- a/libc/test/src/math/smoke/isnanbf16_test.cpp
+++ b/libc/test/src/math/smoke/isnanbf16_test.cpp
@@ -1,11 +1,15 @@
-//===-- Unittests for isnanbf16
-//--------------------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
+///
+/// \brief
+/// This file contains unit tests for isnanbf16.
+///
+//===----------------------------------------------------------------------===//
#include "IsNanTest.h"
#include "src/__support/FPUtil/bfloat16.h"
More information about the libc-commits
mailing list