[libc-commits] [libc] [llvm] [libc][math] Implement isnanbf16 function (PR #238777)
Vaibhav Agrawal via libc-commits
libc-commits at lists.llvm.org
Tue Nov 10 09:50:39 PST 2026
https://github.com/competitive-programmer04 updated https://github.com/llvm/llvm-project/pull/238777
>From 110bd753e90ec26324f88db0c08683b112eb69f6 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 657eb27898f35e..db4813b17ae180 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 4bc97e048cf988..cdd25a651aabdf 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 49c1c05aaabb63..cd1ce171db90bb 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 18d87784c7433a..b1a585717b442d 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 f2554d62f4ae1c..24a85032740ead 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 4f207c4ec6fa75..5526f8fa4bd837 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 0e6cf253a77a97..ceac2bc57ffb55 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 5bb787743a58c5..37373d9ac35918 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 feffcb0590c735..ac798645b274f2 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 3c026f06836e59..59d60864db0f70 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -984,6 +984,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 5bf0f4228d07ed..25fd051fe74cb6 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -731,6 +731,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 b152fecff84e62..2b667b76ac1a8a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1080,6 +1080,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 be9b45cf21339d..21753345a7b4df 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1080,6 +1080,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 a311fa50a71b7a..f8027effc54c0e 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 56654666305c52..3bcd333c5248f3 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 310dce48e2c84d..a181a0aa2d3974 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 88fca3c6b572f7..4ff742fb2499f9 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 aaadf47c771c1b..c49071355bcc7c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3329,6 +3329,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 21c067255ab007..649b8d5f34cc40 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 97e975a238922d..9a3bd5243ba0a7 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 d3e0b3c0803add..02f5b9ff0ada6f 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 3deef74286e4a8..006da8dbac0c28 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -8500,6 +8500,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"],
@@ -13979,6 +13989,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 311dc8856357ff..7b60a5e01adb66 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 48c9514c665ba002ed29663f673d6f5b9fcc4451 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 | 11 ++++++++---
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 | 4 +++-
libc/test/shared/shared_math_test.cpp | 2 +-
libc/test/src/math/smoke/isnanbf16_test.cpp | 8 ++++++--
18 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index db4813b17ae180..6d3010dc56da0e 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 cdd25a651aabdf..1f3fb82fd77da7 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 cd1ce171db90bb..a9e0f979b1d442 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 b1a585717b442d..2719ab51b72c3d 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 24a85032740ead..ad8aedc63a0413 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 37373d9ac35918..1bc180573a6534 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 ac798645b274f2..bf183823f9522f 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 59d60864db0f70..66d4f0878e60a7 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -984,7 +984,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
@@ -1124,6 +1123,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 2b667b76ac1a8a..610a70f0599036 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1080,7 +1080,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
@@ -1226,6 +1225,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 21753345a7b4df..65aecb37dcb1d9 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1080,7 +1080,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
@@ -1226,6 +1225,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..8a65b8bfd5090e 100644
--- a/libc/src/__support/math/isnanbf16.h
+++ b/libc/src/__support/math/isnanbf16.h
@@ -1,23 +1,28 @@
-//===-- 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
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr int isnanbf16(bfloat16 x) {
+LIBC_INLINE LIBC_CONSTEXPR int isnanbf16(bfloat16 x) {
return fputil::FPBits<bfloat16>(x).is_nan();
}
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 649b8d5f34cc40..84218274f1b0cc 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -734,6 +734,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..e40efd534cedc4 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,9 @@ 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)));
+#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 10)
+static_assert(0 == LIBC_NAMESPACE::shared::isnanbf16(bfloat16(0.0)));
+#endif
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 9a3bd5243ba0a7..64461306216138 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));
@@ -958,6 +957,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