[libc-commits] [libc] [llvm] [libc][math] Refactor iscanonical-isnan-issignaling-nan family to header-only (PR #195581)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Sun May 3 21:51:03 PDT 2026
https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/195581
>From a1f402f6472b37e0761d18d79231855cf1e8c848 Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Mon, 4 May 2026 07:24:22 +0300
Subject: [PATCH 1/3] [libc][math] Refactor iscanonical-isnan-issignaling-nan
family to header-only
Refactored functions:
- iscanonical
- iscanonicalbf16
- iscanonicalf
- iscanonicalf128
- iscanonicalf16
- iscanonicall
- isnan
- isnanf
- isnanl
- issignaling
- issignalingbf16
- issignalingf
- issignalingf128
- issignalingf16
- issignalingl
- nan
- nanbf16
- nanf
- nanf128
- nanf16
- nanl
---
libc/shared/math.h | 21 ++
libc/shared/math/iscanonical.h | 23 ++
libc/shared/math/iscanonicalbf16.h | 23 ++
libc/shared/math/iscanonicalf.h | 23 ++
libc/shared/math/iscanonicalf128.h | 29 ++
libc/shared/math/iscanonicalf16.h | 29 ++
libc/shared/math/iscanonicall.h | 23 ++
libc/shared/math/isnan.h | 23 ++
libc/shared/math/isnanf.h | 23 ++
libc/shared/math/isnanl.h | 23 ++
libc/shared/math/issignaling.h | 23 ++
libc/shared/math/issignalingbf16.h | 23 ++
libc/shared/math/issignalingf.h | 23 ++
libc/shared/math/issignalingf128.h | 29 ++
libc/shared/math/issignalingf16.h | 29 ++
libc/shared/math/issignalingl.h | 23 ++
libc/shared/math/nan.h | 23 ++
libc/shared/math/nanbf16.h | 23 ++
libc/shared/math/nanf.h | 23 ++
libc/shared/math/nanf128.h | 29 ++
libc/shared/math/nanf16.h | 29 ++
libc/shared/math/nanl.h | 23 ++
libc/src/__support/FPUtil/BasicOperations.h | 4 +-
libc/src/__support/math/CMakeLists.txt | 201 +++++++++++
libc/src/__support/math/iscanonical.h | 27 ++
libc/src/__support/math/iscanonicalbf16.h | 27 ++
libc/src/__support/math/iscanonicalf.h | 26 ++
libc/src/__support/math/iscanonicalf128.h | 32 ++
libc/src/__support/math/iscanonicalf16.h | 32 ++
libc/src/__support/math/iscanonicall.h | 26 ++
libc/src/__support/math/isnan.h | 22 ++
libc/src/__support/math/isnanf.h | 22 ++
libc/src/__support/math/isnanl.h | 22 ++
libc/src/__support/math/issignaling.h | 25 ++
libc/src/__support/math/issignalingbf16.h | 26 ++
libc/src/__support/math/issignalingf.h | 25 ++
libc/src/__support/math/issignalingf128.h | 31 ++
libc/src/__support/math/issignalingf16.h | 31 ++
libc/src/__support/math/issignalingl.h | 25 ++
libc/src/__support/math/nan.h | 29 ++
libc/src/__support/math/nanbf16.h | 30 ++
libc/src/__support/math/nanf.h | 29 ++
libc/src/__support/math/nanf128.h | 35 ++
libc/src/__support/math/nanf16.h | 35 ++
libc/src/__support/math/nanl.h | 29 ++
libc/src/__support/str_to_float.h | 5 +-
libc/src/__support/str_to_integer.h | 4 +-
libc/src/math/generic/CMakeLists.txt | 43 +--
libc/src/math/generic/iscanonical.cpp | 8 +-
libc/src/math/generic/iscanonicalbf16.cpp | 8 +-
libc/src/math/generic/iscanonicalf.cpp | 7 +-
libc/src/math/generic/iscanonicalf128.cpp | 7 +-
libc/src/math/generic/iscanonicalf16.cpp | 7 +-
libc/src/math/generic/iscanonicall.cpp | 7 +-
libc/src/math/generic/isnan.cpp | 5 +-
libc/src/math/generic/isnanf.cpp | 5 +-
libc/src/math/generic/isnanl.cpp | 5 +-
libc/src/math/generic/issignaling.cpp | 6 +-
libc/src/math/generic/issignalingbf16.cpp | 7 +-
libc/src/math/generic/issignalingf.cpp | 6 +-
libc/src/math/generic/issignalingf128.cpp | 6 +-
libc/src/math/generic/issignalingf16.cpp | 6 +-
libc/src/math/generic/issignalingl.cpp | 6 +-
libc/src/math/generic/nan.cpp | 12 +-
libc/src/math/generic/nanbf16.cpp | 11 +-
libc/src/math/generic/nanf.cpp | 12 +-
libc/src/math/generic/nanf128.cpp | 10 +-
libc/src/math/generic/nanf16.cpp | 10 +-
libc/src/math/generic/nanl.cpp | 10 +-
libc/test/shared/CMakeLists.txt | 42 +++
.../shared/shared_math_constexpr_test.cpp | 49 +++
libc/test/shared/shared_math_test.cpp | 20 ++
.../llvm-project-overlay/libc/BUILD.bazel | 317 ++++++++++++++++--
73 files changed, 1795 insertions(+), 177 deletions(-)
create mode 100644 libc/shared/math/iscanonical.h
create mode 100644 libc/shared/math/iscanonicalbf16.h
create mode 100644 libc/shared/math/iscanonicalf.h
create mode 100644 libc/shared/math/iscanonicalf128.h
create mode 100644 libc/shared/math/iscanonicalf16.h
create mode 100644 libc/shared/math/iscanonicall.h
create mode 100644 libc/shared/math/isnan.h
create mode 100644 libc/shared/math/isnanf.h
create mode 100644 libc/shared/math/isnanl.h
create mode 100644 libc/shared/math/issignaling.h
create mode 100644 libc/shared/math/issignalingbf16.h
create mode 100644 libc/shared/math/issignalingf.h
create mode 100644 libc/shared/math/issignalingf128.h
create mode 100644 libc/shared/math/issignalingf16.h
create mode 100644 libc/shared/math/issignalingl.h
create mode 100644 libc/shared/math/nan.h
create mode 100644 libc/shared/math/nanbf16.h
create mode 100644 libc/shared/math/nanf.h
create mode 100644 libc/shared/math/nanf128.h
create mode 100644 libc/shared/math/nanf16.h
create mode 100644 libc/shared/math/nanl.h
create mode 100644 libc/src/__support/math/iscanonical.h
create mode 100644 libc/src/__support/math/iscanonicalbf16.h
create mode 100644 libc/src/__support/math/iscanonicalf.h
create mode 100644 libc/src/__support/math/iscanonicalf128.h
create mode 100644 libc/src/__support/math/iscanonicalf16.h
create mode 100644 libc/src/__support/math/iscanonicall.h
create mode 100644 libc/src/__support/math/isnan.h
create mode 100644 libc/src/__support/math/isnanf.h
create mode 100644 libc/src/__support/math/isnanl.h
create mode 100644 libc/src/__support/math/issignaling.h
create mode 100644 libc/src/__support/math/issignalingbf16.h
create mode 100644 libc/src/__support/math/issignalingf.h
create mode 100644 libc/src/__support/math/issignalingf128.h
create mode 100644 libc/src/__support/math/issignalingf16.h
create mode 100644 libc/src/__support/math/issignalingl.h
create mode 100644 libc/src/__support/math/nan.h
create mode 100644 libc/src/__support/math/nanbf16.h
create mode 100644 libc/src/__support/math/nanf.h
create mode 100644 libc/src/__support/math/nanf128.h
create mode 100644 libc/src/__support/math/nanf16.h
create mode 100644 libc/src/__support/math/nanl.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bed4279f621a0..dc75a8b78cd8e 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -281,6 +281,21 @@
#include "math/ilogbf128.h"
#include "math/ilogbf16.h"
#include "math/ilogbl.h"
+#include "math/iscanonical.h"
+#include "math/iscanonicalbf16.h"
+#include "math/iscanonicalf.h"
+#include "math/iscanonicalf128.h"
+#include "math/iscanonicalf16.h"
+#include "math/iscanonicall.h"
+#include "math/isnan.h"
+#include "math/isnanf.h"
+#include "math/isnanl.h"
+#include "math/issignaling.h"
+#include "math/issignalingbf16.h"
+#include "math/issignalingf.h"
+#include "math/issignalingf128.h"
+#include "math/issignalingf16.h"
+#include "math/issignalingl.h"
#include "math/ldexp.h"
#include "math/ldexpbf16.h"
#include "math/ldexpf.h"
@@ -343,6 +358,12 @@
#include "math/modff128.h"
#include "math/modff16.h"
#include "math/modfl.h"
+#include "math/nan.h"
+#include "math/nanbf16.h"
+#include "math/nanf.h"
+#include "math/nanf128.h"
+#include "math/nanf16.h"
+#include "math/nanl.h"
#include "math/nearbyint.h"
#include "math/nearbyintbf16.h"
#include "math/nearbyintf.h"
diff --git a/libc/shared/math/iscanonical.h b/libc/shared/math/iscanonical.h
new file mode 100644
index 0000000000000..6b9f8514e1eee
--- /dev/null
+++ b/libc/shared/math/iscanonical.h
@@ -0,0 +1,23 @@
+//===-- Shared iscanonical 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_ISCANONICAL_H
+#define LLVM_LIBC_SHARED_MATH_ISCANONICAL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/iscanonical.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::iscanonical;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISCANONICAL_H
diff --git a/libc/shared/math/iscanonicalbf16.h b/libc/shared/math/iscanonicalbf16.h
new file mode 100644
index 0000000000000..15f10de00fd9d
--- /dev/null
+++ b/libc/shared/math/iscanonicalbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared iscanonicalbf16 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_ISCANONICALBF16_H
+#define LLVM_LIBC_SHARED_MATH_ISCANONICALBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/iscanonicalbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::iscanonicalbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISCANONICALBF16_H
diff --git a/libc/shared/math/iscanonicalf.h b/libc/shared/math/iscanonicalf.h
new file mode 100644
index 0000000000000..0770fbd8f8b1e
--- /dev/null
+++ b/libc/shared/math/iscanonicalf.h
@@ -0,0 +1,23 @@
+//===-- Shared iscanonicalf 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_ISCANONICALF_H
+#define LLVM_LIBC_SHARED_MATH_ISCANONICALF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/iscanonicalf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::iscanonicalf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISCANONICALF_H
diff --git a/libc/shared/math/iscanonicalf128.h b/libc/shared/math/iscanonicalf128.h
new file mode 100644
index 0000000000000..f8494304a804a
--- /dev/null
+++ b/libc/shared/math/iscanonicalf128.h
@@ -0,0 +1,29 @@
+//===-- Shared iscanonicalf128 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_ISCANONICALF128_H
+#define LLVM_LIBC_SHARED_MATH_ISCANONICALF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/iscanonicalf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::iscanonicalf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ISCANONICALF128_H
diff --git a/libc/shared/math/iscanonicalf16.h b/libc/shared/math/iscanonicalf16.h
new file mode 100644
index 0000000000000..1f6fa797625fc
--- /dev/null
+++ b/libc/shared/math/iscanonicalf16.h
@@ -0,0 +1,29 @@
+//===-- Shared iscanonicalf16 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_ISCANONICALF16_H
+#define LLVM_LIBC_SHARED_MATH_ISCANONICALF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/iscanonicalf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::iscanonicalf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ISCANONICALF16_H
diff --git a/libc/shared/math/iscanonicall.h b/libc/shared/math/iscanonicall.h
new file mode 100644
index 0000000000000..d3558b0292c8f
--- /dev/null
+++ b/libc/shared/math/iscanonicall.h
@@ -0,0 +1,23 @@
+//===-- Shared iscanonicall 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_ISCANONICALL_H
+#define LLVM_LIBC_SHARED_MATH_ISCANONICALL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/iscanonicall.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::iscanonicall;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISCANONICALL_H
diff --git a/libc/shared/math/isnan.h b/libc/shared/math/isnan.h
new file mode 100644
index 0000000000000..6039f309d3255
--- /dev/null
+++ b/libc/shared/math/isnan.h
@@ -0,0 +1,23 @@
+//===-- Shared isnan 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_ISNAN_H
+#define LLVM_LIBC_SHARED_MATH_ISNAN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnan.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::isnan;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISNAN_H
diff --git a/libc/shared/math/isnanf.h b/libc/shared/math/isnanf.h
new file mode 100644
index 0000000000000..2858342fb13c0
--- /dev/null
+++ b/libc/shared/math/isnanf.h
@@ -0,0 +1,23 @@
+//===-- Shared isnanf 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_ISNANF_H
+#define LLVM_LIBC_SHARED_MATH_ISNANF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnanf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::isnanf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISNANF_H
diff --git a/libc/shared/math/isnanl.h b/libc/shared/math/isnanl.h
new file mode 100644
index 0000000000000..4cc3b90b5bcf7
--- /dev/null
+++ b/libc/shared/math/isnanl.h
@@ -0,0 +1,23 @@
+//===-- Shared isnanl 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_ISNANL_H
+#define LLVM_LIBC_SHARED_MATH_ISNANL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnanl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::isnanl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISNANL_H
diff --git a/libc/shared/math/issignaling.h b/libc/shared/math/issignaling.h
new file mode 100644
index 0000000000000..eb766e9d8f8be
--- /dev/null
+++ b/libc/shared/math/issignaling.h
@@ -0,0 +1,23 @@
+//===-- Shared issignaling 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_ISSIGNALING_H
+#define LLVM_LIBC_SHARED_MATH_ISSIGNALING_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/issignaling.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::issignaling;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISSIGNALING_H
diff --git a/libc/shared/math/issignalingbf16.h b/libc/shared/math/issignalingbf16.h
new file mode 100644
index 0000000000000..51dc3ca86ff7e
--- /dev/null
+++ b/libc/shared/math/issignalingbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared issignalingbf16 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_ISSIGNALINGBF16_H
+#define LLVM_LIBC_SHARED_MATH_ISSIGNALINGBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/issignalingbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::issignalingbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISSIGNALINGBF16_H
diff --git a/libc/shared/math/issignalingf.h b/libc/shared/math/issignalingf.h
new file mode 100644
index 0000000000000..7addc45b7f86b
--- /dev/null
+++ b/libc/shared/math/issignalingf.h
@@ -0,0 +1,23 @@
+//===-- Shared issignalingf 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_ISSIGNALINGF_H
+#define LLVM_LIBC_SHARED_MATH_ISSIGNALINGF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/issignalingf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::issignalingf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISSIGNALINGF_H
diff --git a/libc/shared/math/issignalingf128.h b/libc/shared/math/issignalingf128.h
new file mode 100644
index 0000000000000..08c295c640680
--- /dev/null
+++ b/libc/shared/math/issignalingf128.h
@@ -0,0 +1,29 @@
+//===-- Shared issignalingf128 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_ISSIGNALINGF128_H
+#define LLVM_LIBC_SHARED_MATH_ISSIGNALINGF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/issignalingf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::issignalingf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ISSIGNALINGF128_H
diff --git a/libc/shared/math/issignalingf16.h b/libc/shared/math/issignalingf16.h
new file mode 100644
index 0000000000000..bfb33f9cab931
--- /dev/null
+++ b/libc/shared/math/issignalingf16.h
@@ -0,0 +1,29 @@
+//===-- Shared issignalingf16 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_ISSIGNALINGF16_H
+#define LLVM_LIBC_SHARED_MATH_ISSIGNALINGF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/issignalingf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::issignalingf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ISSIGNALINGF16_H
diff --git a/libc/shared/math/issignalingl.h b/libc/shared/math/issignalingl.h
new file mode 100644
index 0000000000000..a0453ecdf48d8
--- /dev/null
+++ b/libc/shared/math/issignalingl.h
@@ -0,0 +1,23 @@
+//===-- Shared issignalingl 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_ISSIGNALINGL_H
+#define LLVM_LIBC_SHARED_MATH_ISSIGNALINGL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/issignalingl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::issignalingl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISSIGNALINGL_H
diff --git a/libc/shared/math/nan.h b/libc/shared/math/nan.h
new file mode 100644
index 0000000000000..b33903f6e17aa
--- /dev/null
+++ b/libc/shared/math/nan.h
@@ -0,0 +1,23 @@
+//===-- Shared nan 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_NAN_H
+#define LLVM_LIBC_SHARED_MATH_NAN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nan.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nan;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NAN_H
diff --git a/libc/shared/math/nanbf16.h b/libc/shared/math/nanbf16.h
new file mode 100644
index 0000000000000..3a5bdcff21b17
--- /dev/null
+++ b/libc/shared/math/nanbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nanbf16 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_NANBF16_H
+#define LLVM_LIBC_SHARED_MATH_NANBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nanbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nanbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NANBF16_H
diff --git a/libc/shared/math/nanf.h b/libc/shared/math/nanf.h
new file mode 100644
index 0000000000000..37c0bd3589c5b
--- /dev/null
+++ b/libc/shared/math/nanf.h
@@ -0,0 +1,23 @@
+//===-- Shared nanf 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_NANF_H
+#define LLVM_LIBC_SHARED_MATH_NANF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nanf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nanf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NANF_H
diff --git a/libc/shared/math/nanf128.h b/libc/shared/math/nanf128.h
new file mode 100644
index 0000000000000..60ce05a3d5eda
--- /dev/null
+++ b/libc/shared/math/nanf128.h
@@ -0,0 +1,29 @@
+//===-- Shared nanf128 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_NANF128_H
+#define LLVM_LIBC_SHARED_MATH_NANF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nanf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nanf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_NANF128_H
diff --git a/libc/shared/math/nanf16.h b/libc/shared/math/nanf16.h
new file mode 100644
index 0000000000000..a82e7dec5b161
--- /dev/null
+++ b/libc/shared/math/nanf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nanf16 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_NANF16_H
+#define LLVM_LIBC_SHARED_MATH_NANF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nanf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nanf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NANF16_H
diff --git a/libc/shared/math/nanl.h b/libc/shared/math/nanl.h
new file mode 100644
index 0000000000000..859699629ca4c
--- /dev/null
+++ b/libc/shared/math/nanl.h
@@ -0,0 +1,23 @@
+//===-- Shared nanl 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_NANL_H
+#define LLVM_LIBC_SHARED_MATH_NANL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nanl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nanl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NANL_H
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index e6f5f29e73726..40294d896b889 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -275,13 +275,13 @@ LIBC_INLINE T constexpr fdim(T x, T y) {
// Avoid reusing `issignaling` macro.
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE int issignaling_impl(const T &x) {
+LIBC_INLINE constexpr int issignaling_impl(const T &x) {
FPBits<T> sx(x);
return sx.is_signaling_nan();
}
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE int canonicalize(T &cx, const T &x) {
+LIBC_INLINE constexpr int canonicalize(T &cx, const T &x) {
FPBits<T> sx(x);
if constexpr (get_fp_type<T>() == FPType::X86_Binary80) {
// All the pseudo and unnormal numbers are not canonical.
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index a7d08c2d40cb5..334975932e905 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1620,6 +1620,143 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ iscanonical
+ HDRS
+ iscanonical.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ iscanonicalbf16
+ HDRS
+ iscanonicalbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ iscanonicalf
+ HDRS
+ iscanonicalf.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ iscanonicalf128
+ HDRS
+ iscanonicalf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ iscanonicalf16
+ HDRS
+ iscanonicalf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ iscanonicall
+ HDRS
+ iscanonicall.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ isnan
+ HDRS
+ isnan.h
+ DEPENDS
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ isnanf
+ HDRS
+ isnanf.h
+ DEPENDS
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ isnanl
+ HDRS
+ isnanl.h
+ DEPENDS
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ issignaling
+ HDRS
+ issignaling.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ issignalingbf16
+ HDRS
+ issignalingbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ issignalingf
+ HDRS
+ issignalingf.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ issignalingf128
+ HDRS
+ issignalingf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ issignalingf16
+ HDRS
+ issignalingf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ issignalingl
+ HDRS
+ issignalingl.h
+ DEPENDS
+ libc.src.__support.macros.config
+ libc.src.__support.FPUtil.basic_operations
+)
add_header_library(
ldexp
@@ -1954,6 +2091,70 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ nan
+ HDRS
+ nan.h
+ DEPENDS
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
+ libc.src.__support.str_to_float
+
+)
+
+add_header_library(
+ nanbf16
+ HDRS
+ nanbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
+ libc.src.__support.str_to_float
+)
+
+add_header_library(
+ nanf
+ HDRS
+ nanf.h
+ DEPENDS
+ libc.src.__support.macros.config
+ libc.src.__support.str_to_float
+ libc.src.__support.libc_errno
+)
+
+add_header_library(
+ nanf128
+ HDRS
+ nanf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.macros.config
+ libc.src.__support.str_to_float
+ libc.src.__support.libc_errno
+)
+
+add_header_library(
+ nanf16
+ HDRS
+ nanf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.macros.config
+ libc.src.__support.str_to_float
+ libc.src.__support.libc_errno
+)
+
+add_header_library(
+ nanl
+ HDRS
+ nanl.h
+ DEPENDS
+ libc.src.__support.macros.config
+ libc.src.__support.str_to_float
+ libc.src.__support.libc_errno
+)
+
add_header_library(
nearbyint
HDRS
diff --git a/libc/src/__support/math/iscanonical.h b/libc/src/__support/math/iscanonical.h
new file mode 100644
index 0000000000000..db0388c150eeb
--- /dev/null
+++ b/libc/src/__support/math/iscanonical.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for iscanonical -------------------*- 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_ISCANONICAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICAL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+#undef iscanonical
+LIBC_INLINE constexpr int iscanonical(double x) {
+ double temp{};
+ return fputil::canonicalize(temp, x) == 0;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICAL_H
diff --git a/libc/src/__support/math/iscanonicalbf16.h b/libc/src/__support/math/iscanonicalbf16.h
new file mode 100644
index 0000000000000..8072fad9323ac
--- /dev/null
+++ b/libc/src/__support/math/iscanonicalbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for iscanonicalbf16 ---------------*- 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_ISCANONICALBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int iscanonicalbf16(bfloat16 x) {
+ bfloat16 tmp{};
+ return fputil::canonicalize(tmp, x) == 0;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALBF16_H
diff --git a/libc/src/__support/math/iscanonicalf.h b/libc/src/__support/math/iscanonicalf.h
new file mode 100644
index 0000000000000..bff6cfaed26a5
--- /dev/null
+++ b/libc/src/__support/math/iscanonicalf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for iscanonicalf ------------------*- 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_ISCANONICALF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int iscanonicalf(float x) {
+ float temp{};
+ return fputil::canonicalize(temp, x) == 0;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALF_H
diff --git a/libc/src/__support/math/iscanonicalf128.h b/libc/src/__support/math/iscanonicalf128.h
new file mode 100644
index 0000000000000..6153879dfa7b2
--- /dev/null
+++ b/libc/src/__support/math/iscanonicalf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for iscanonicalf128 ---------------*- 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_ISCANONICALF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int iscanonicalf128(float128 x) {
+ float128 temp{};
+ return fputil::canonicalize(temp, x) == 0;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALF128_H
diff --git a/libc/src/__support/math/iscanonicalf16.h b/libc/src/__support/math/iscanonicalf16.h
new file mode 100644
index 0000000000000..e152e13cbfccb
--- /dev/null
+++ b/libc/src/__support/math/iscanonicalf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for iscanonicalf16 ----------------*- 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_ISCANONICALF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int iscanonicalf16(float16 x) {
+ float16 temp{};
+ return fputil::canonicalize(temp, x) == 0;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALF16_H
diff --git a/libc/src/__support/math/iscanonicall.h b/libc/src/__support/math/iscanonicall.h
new file mode 100644
index 0000000000000..e989441be2655
--- /dev/null
+++ b/libc/src/__support/math/iscanonicall.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for iscanonicall ------------------*- 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_ISCANONICALL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int iscanonicall(long double x) {
+ long double temp{};
+ return fputil::canonicalize(temp, x) == 0;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISCANONICALL_H
diff --git a/libc/src/__support/math/isnan.h b/libc/src/__support/math/isnan.h
new file mode 100644
index 0000000000000..35bd8b55f571e
--- /dev/null
+++ b/libc/src/__support/math/isnan.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for isnan -------------------------*- 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_ISNAN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNAN_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int isnan(double x) { return __builtin_isnan(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNAN_H
diff --git a/libc/src/__support/math/isnanf.h b/libc/src/__support/math/isnanf.h
new file mode 100644
index 0000000000000..3ab65b9623894
--- /dev/null
+++ b/libc/src/__support/math/isnanf.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for isnanf ------------------------*- 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_ISNANF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNANF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int isnanf(float x) { return __builtin_isnan(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNANF_H
diff --git a/libc/src/__support/math/isnanl.h b/libc/src/__support/math/isnanl.h
new file mode 100644
index 0000000000000..d896f7fa3e094
--- /dev/null
+++ b/libc/src/__support/math/isnanl.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for isnanl ------------------------*- 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_ISNANL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNANL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int isnanl(long double x) { return __builtin_isnan(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNANL_H
diff --git a/libc/src/__support/math/issignaling.h b/libc/src/__support/math/issignaling.h
new file mode 100644
index 0000000000000..dabd3d2e93625
--- /dev/null
+++ b/libc/src/__support/math/issignaling.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for issignaling -------------------*- 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_ISSIGNALING_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALING_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int issignaling(double x) {
+ return fputil::issignaling_impl(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALING_H
diff --git a/libc/src/__support/math/issignalingbf16.h b/libc/src/__support/math/issignalingbf16.h
new file mode 100644
index 0000000000000..3db72dcec52f4
--- /dev/null
+++ b/libc/src/__support/math/issignalingbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for issignalingbf16 ---------------*- 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_ISSIGNALINGBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int issignalingbf16(bfloat16 x) {
+ return fputil::issignaling_impl(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGBF16_H
diff --git a/libc/src/__support/math/issignalingf.h b/libc/src/__support/math/issignalingf.h
new file mode 100644
index 0000000000000..40d08edd1b342
--- /dev/null
+++ b/libc/src/__support/math/issignalingf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for issignalingf ------------------*- 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_ISSIGNALINGF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int issignalingf(float x) {
+ return fputil::issignaling_impl(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGF_H
diff --git a/libc/src/__support/math/issignalingf128.h b/libc/src/__support/math/issignalingf128.h
new file mode 100644
index 0000000000000..6887ffe586659
--- /dev/null
+++ b/libc/src/__support/math/issignalingf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for issignalingf128 ---------------*- 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_ISSIGNALINGF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int issignalingf128(float128 x) {
+ return fputil::issignaling_impl(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGF128_H
diff --git a/libc/src/__support/math/issignalingf16.h b/libc/src/__support/math/issignalingf16.h
new file mode 100644
index 0000000000000..3f655e8bf381c
--- /dev/null
+++ b/libc/src/__support/math/issignalingf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for issignalingf16 ----------------*- 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_ISSIGNALINGF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int issignalingf16(float16 x) {
+ return fputil::issignaling_impl(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGF16_H
diff --git a/libc/src/__support/math/issignalingl.h b/libc/src/__support/math/issignalingl.h
new file mode 100644
index 0000000000000..ac2e40b0ee51e
--- /dev/null
+++ b/libc/src/__support/math/issignalingl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for issignalingl ------------------*- 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_ISSIGNALINGL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int issignalingl(long double x) {
+ return fputil::issignaling_impl(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISSIGNALINGL_H
diff --git a/libc/src/__support/math/nan.h b/libc/src/__support/math/nan.h
new file mode 100644
index 0000000000000..35d89e05b7b53
--- /dev/null
+++ b/libc/src/__support/math/nan.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for nan ---------------------------*- 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_NAN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NAN_H
+
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double nan(const char *arg) {
+ auto result = internal::strtonan<double>(arg);
+ if (result.has_error())
+ libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NAN_H
diff --git a/libc/src/__support/math/nanbf16.h b/libc/src/__support/math/nanbf16.h
new file mode 100644
index 0000000000000..81638f0cc2fcf
--- /dev/null
+++ b/libc/src/__support/math/nanbf16.h
@@ -0,0 +1,30 @@
+//===-- Implementation header for nanbf16 -----------------------*- 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_NANBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NANBF16_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 nanbf16(const char *arg) {
+ auto result = internal::strtonan<bfloat16>(arg);
+ if (result.has_error())
+ libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NANBF16_H
diff --git a/libc/src/__support/math/nanf.h b/libc/src/__support/math/nanf.h
new file mode 100644
index 0000000000000..d743d3e949fc8
--- /dev/null
+++ b/libc/src/__support/math/nanf.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for nanf --------------------------*- 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_NANF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NANF_H
+
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float nanf(const char *arg) {
+ auto result = internal::strtonan<float>(arg);
+ if (result.has_error())
+ libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NANF_H
diff --git a/libc/src/__support/math/nanf128.h b/libc/src/__support/math/nanf128.h
new file mode 100644
index 0000000000000..bb5c4e0a4f1f2
--- /dev/null
+++ b/libc/src/__support/math/nanf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for nanf128 -----------------------*- 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_NANF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 nanf128(const char *arg) {
+ auto result = internal::strtonan<float128>(arg);
+ if (result.has_error())
+ libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NANF128_H
diff --git a/libc/src/__support/math/nanf16.h b/libc/src/__support/math/nanf16.h
new file mode 100644
index 0000000000000..cce5ab7c11b6d
--- /dev/null
+++ b/libc/src/__support/math/nanf16.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for nanf16 ------------------------*- 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_NANF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NANF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 nanf16(const char *arg) {
+ auto result = internal::strtonan<float16>(arg);
+ if (result.has_error())
+ libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NANF16_H
diff --git a/libc/src/__support/math/nanl.h b/libc/src/__support/math/nanl.h
new file mode 100644
index 0000000000000..b7f8b7de42971
--- /dev/null
+++ b/libc/src/__support/math/nanl.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for nanl --------------------------*- 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_NANL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NANL_H
+
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double nanl(const char *arg) {
+ auto result = internal::strtonan<long double>(arg);
+ if (result.has_error())
+ libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NANL_H
diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index b48d29ff896e1..830db2485fad8 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -1093,7 +1093,7 @@ hexadecimal_string_to_float(const CharType *__restrict src,
}
template <typename T, typename CharType>
-LIBC_INLINE typename fputil::FPBits<T>::StorageType
+LIBC_INLINE constexpr typename fputil::FPBits<T>::StorageType
nan_mantissa_from_ncharseq(const CharType *str, size_t len) {
using FPBits = typename fputil::FPBits<T>;
using StorageType = typename FPBits::StorageType;
@@ -1221,7 +1221,8 @@ strtofloatingpoint(const CharType *__restrict src) {
return {result.get_val(), static_cast<ptrdiff_t>(index), error};
}
-template <class T> LIBC_INLINE StrToNumResult<T> strtonan(const char *arg) {
+template <class T>
+LIBC_INLINE constexpr StrToNumResult<T> strtonan(const char *arg) {
using FPBits = typename fputil::FPBits<T>;
using StorageType = typename FPBits::StorageType;
diff --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h
index 2df1ea894e53a..36f1d05eb2844 100644
--- a/libc/src/__support/str_to_integer.h
+++ b/libc/src/__support/str_to_integer.h
@@ -33,7 +33,7 @@ namespace internal {
// Returns the idx to the first character in src that is not a whitespace
// character (as determined by isspace())
template <typename CharType>
-LIBC_INLINE size_t
+LIBC_INLINE constexpr size_t
first_non_whitespace(const CharType *__restrict src,
size_t src_len = cpp::numeric_limits<size_t>::max()) {
size_t src_cur = 0;
@@ -94,7 +94,7 @@ LIBC_INLINE static int infer_base(const CharType *__restrict src,
// Takes a pointer to a string and the base to convert to. This function is used
// as the backend for all of the string to int functions.
template <typename T, typename CharType>
-LIBC_INLINE StrToNumResult<T>
+LIBC_INLINE constexpr StrToNumResult<T>
strtointeger(const CharType *__restrict src, int base,
const size_t src_len = cpp::numeric_limits<size_t>::max()) {
using ResultType = make_integral_or_big_int_unsigned_t<T>;
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d925a2817c177..e4ec5838eda4e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -91,7 +91,7 @@ add_entrypoint_object(
HDRS
../iscanonicalf16.h
DEPENDS
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.iscanonicall
)
add_entrypoint_object(
@@ -101,7 +101,7 @@ add_entrypoint_object(
HDRS
../iscanonicalf128.h
DEPENDS
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.iscanonicalf128
)
add_entrypoint_object(
@@ -111,11 +111,7 @@ add_entrypoint_object(
HDRS
../iscanonicalbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
- libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.math.iscanonicalbf16
)
add_entrypoint_object(
@@ -3040,7 +3036,7 @@ add_entrypoint_object(
HDRS
../issignalingf16.h
DEPENDS
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.issignalingl
)
add_entrypoint_object(
@@ -3050,7 +3046,7 @@ add_entrypoint_object(
HDRS
../issignalingf128.h
DEPENDS
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.issignalingf128
)
add_entrypoint_object(
@@ -3060,11 +3056,7 @@ add_entrypoint_object(
HDRS
../issignalingbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
- libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.math.issignalingbf16
)
add_entrypoint_object(
@@ -3098,8 +3090,7 @@ add_entrypoint_object(
HDRS
../nan.h
DEPENDS
- libc.src.__support.str_to_float
- libc.src.errno.errno
+ libc.src.__support.math.nan
)
add_entrypoint_object(
@@ -3109,8 +3100,7 @@ add_entrypoint_object(
HDRS
../nanf.h
DEPENDS
- libc.src.__support.str_to_float
- libc.src.errno.errno
+ libc.src.__support.math.nanf
)
add_entrypoint_object(
@@ -3120,8 +3110,7 @@ add_entrypoint_object(
HDRS
../nanl.h
DEPENDS
- libc.src.__support.str_to_float
- libc.src.errno.errno
+ libc.src.__support.math.nanl
)
add_entrypoint_object(
@@ -3131,8 +3120,7 @@ add_entrypoint_object(
HDRS
../nanf16.h
DEPENDS
- libc.src.__support.str_to_float
- libc.src.errno.errno
+ libc.src.__support.math.nanf16
)
add_entrypoint_object(
@@ -3142,8 +3130,7 @@ add_entrypoint_object(
HDRS
../nanf128.h
DEPENDS
- libc.src.__support.str_to_float
- libc.src.errno.errno
+ libc.src.__support.math.nanf128
)
add_entrypoint_object(
@@ -3153,13 +3140,7 @@ add_entrypoint_object(
HDRS
../nanbf16.h
DEPENDS
- libc.src.errno.errno
- libc.src.__support.common
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.libc_errno
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
- libc.src.__support.str_to_float
+ libc.src.__support.math.nanbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index ff922f3ae8ee7..583be8853287b 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/iscanonical.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/iscanonical.h"
namespace LIBC_NAMESPACE_DECL {
-#undef iscanonical
LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
- double temp;
- return fputil::canonicalize(temp, x) == 0;
+ return math::iscanonical(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalbf16.cpp b/libc/src/math/generic/iscanonicalbf16.cpp
index 34c11bfcb83d5..ac330d9c9408f 100644
--- a/libc/src/math/generic/iscanonicalbf16.cpp
+++ b/libc/src/math/generic/iscanonicalbf16.cpp
@@ -7,16 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/iscanonicalbf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/iscanonicalbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalbf16, (bfloat16 x)) {
- bfloat16 tmp;
- return fputil::canonicalize(tmp, x) == 0;
+ return math::iscanonicalbf16(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index 5c38e9b72ec58..fc48a68164f6e 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/iscanonicalf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/iscanonicalf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
- float temp;
- return fputil::canonicalize(temp, x) == 0;
+ return math::iscanonicalf(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf128.cpp b/libc/src/math/generic/iscanonicalf128.cpp
index ff549c3194cba..d2bb749b7b461 100644
--- a/libc/src/math/generic/iscanonicalf128.cpp
+++ b/libc/src/math/generic/iscanonicalf128.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/iscanonicalf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/iscanonicalf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf128, (float128 x)) {
- float128 temp;
- return fputil::canonicalize(temp, x) == 0;
+ return math::iscanonicalf128(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf16.cpp b/libc/src/math/generic/iscanonicalf16.cpp
index f9b093dc8ff2d..296dbf6ce06f6 100644
--- a/libc/src/math/generic/iscanonicalf16.cpp
+++ b/libc/src/math/generic/iscanonicalf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/iscanonicalf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/iscanonicalf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf16, (float16 x)) {
- float16 temp;
- return fputil::canonicalize(temp, x) == 0;
+ return math::iscanonicalf16(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 34e00359912b7..a57918f6d2c2c 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/iscanonicall.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/iscanonicall.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
- long double temp;
- return fputil::canonicalize(temp, x) == 0;
+ return math::iscanonicall(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/isnan.cpp b/libc/src/math/generic/isnan.cpp
index 73230a4e9a299..68392a709ca8d 100644
--- a/libc/src/math/generic/isnan.cpp
+++ b/libc/src/math/generic/isnan.cpp
@@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/isnan.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/isnan.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, isnan, (double x)) { return __builtin_isnan(x); }
+LLVM_LIBC_FUNCTION(int, isnan, (double x)) { return math::isnan(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/isnanf.cpp b/libc/src/math/generic/isnanf.cpp
index a1d814eab1825..40cdb01297c2a 100644
--- a/libc/src/math/generic/isnanf.cpp
+++ b/libc/src/math/generic/isnanf.cpp
@@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/isnanf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/isnanf.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, isnanf, (float x)) { return __builtin_isnan(x); }
+LLVM_LIBC_FUNCTION(int, isnanf, (float x)) { return math::isnanf(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/isnanl.cpp b/libc/src/math/generic/isnanl.cpp
index 57ce79f3c7b47..b9bd4518e9475 100644
--- a/libc/src/math/generic/isnanl.cpp
+++ b/libc/src/math/generic/isnanl.cpp
@@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/isnanl.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/isnanl.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, isnanl, (long double x)) { return __builtin_isnan(x); }
+LLVM_LIBC_FUNCTION(int, isnanl, (long double x)) { return math::isnanl(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/issignaling.cpp b/libc/src/math/generic/issignaling.cpp
index 657be5ec50156..336ec88989377 100644
--- a/libc/src/math/generic/issignaling.cpp
+++ b/libc/src/math/generic/issignaling.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/issignaling.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/issignaling.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, issignaling, (double x)) {
- return fputil::issignaling_impl(x);
+ return math::issignaling(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/issignalingbf16.cpp b/libc/src/math/generic/issignalingbf16.cpp
index 3bb17efaa0ffe..3abf4e7c541e0 100644
--- a/libc/src/math/generic/issignalingbf16.cpp
+++ b/libc/src/math/generic/issignalingbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/issignalingbf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/issignalingbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, issignalingbf16, (bfloat16 x)) {
- return fputil::issignaling_impl(x);
+ return math::issignalingbf16(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/issignalingf.cpp b/libc/src/math/generic/issignalingf.cpp
index 8a8003a2609dc..1fdf51c1d287e 100644
--- a/libc/src/math/generic/issignalingf.cpp
+++ b/libc/src/math/generic/issignalingf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/issignalingf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/issignalingf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, issignalingf, (float x)) {
- return fputil::issignaling_impl(x);
+ return math::issignalingf(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/issignalingf128.cpp b/libc/src/math/generic/issignalingf128.cpp
index adf0ebac85bd0..3a42b9f1bc406 100644
--- a/libc/src/math/generic/issignalingf128.cpp
+++ b/libc/src/math/generic/issignalingf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/issignalingf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/issignalingf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, issignalingf128, (float128 x)) {
- return fputil::issignaling_impl(x);
+ return math::issignalingf128(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/issignalingf16.cpp b/libc/src/math/generic/issignalingf16.cpp
index 68a771e7f898b..a7d071dbb7fd5 100644
--- a/libc/src/math/generic/issignalingf16.cpp
+++ b/libc/src/math/generic/issignalingf16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/issignalingf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/issignalingf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, issignalingf16, (float16 x)) {
- return fputil::issignaling_impl(x);
+ return math::issignalingf16(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/issignalingl.cpp b/libc/src/math/generic/issignalingl.cpp
index b993c5559461e..405ed58a4f96b 100644
--- a/libc/src/math/generic/issignalingl.cpp
+++ b/libc/src/math/generic/issignalingl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/issignalingl.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/issignalingl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, issignalingl, (long double x)) {
- return fputil::issignaling_impl(x);
+ return math::issignalingl(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nan.cpp b/libc/src/math/generic/nan.cpp
index 829a2ea435ac0..f64014f01a756 100644
--- a/libc/src/math/generic/nan.cpp
+++ b/libc/src/math/generic/nan.cpp
@@ -7,18 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/nan.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/str_to_float.h"
+#include "src/__support/math/nan.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(double, nan, (const char *arg)) {
- auto result = internal::strtonan<double>(arg);
- if (result.has_error())
- libc_errno = result.error;
- return result.value;
-}
+LLVM_LIBC_FUNCTION(double, nan, (const char *arg)) { return math::nan(arg); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nanbf16.cpp b/libc/src/math/generic/nanbf16.cpp
index 678dd6aed9ee3..d53c50efc5a67 100644
--- a/libc/src/math/generic/nanbf16.cpp
+++ b/libc/src/math/generic/nanbf16.cpp
@@ -7,19 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nanbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/str_to_float.h"
+#include "src/__support/math/nanbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, nanbf16, (const char *arg)) {
- auto result = internal::strtonan<bfloat16>(arg);
- if (result.has_error())
- libc_errno = result.error;
- return result.value;
+ return math::nanbf16(arg);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nanf.cpp b/libc/src/math/generic/nanf.cpp
index 1cb66160e736e..f96671f2b3071 100644
--- a/libc/src/math/generic/nanf.cpp
+++ b/libc/src/math/generic/nanf.cpp
@@ -7,18 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/nanf.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/str_to_float.h"
+#include "src/__support/math/nanf.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, nanf, (const char *arg)) {
- auto result = internal::strtonan<float>(arg);
- if (result.has_error())
- libc_errno = result.error;
- return result.value;
-}
+LLVM_LIBC_FUNCTION(float, nanf, (const char *arg)) { return math::nanf(arg); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nanf128.cpp b/libc/src/math/generic/nanf128.cpp
index 4155c5333a9c2..04cb5cf03cc74 100644
--- a/libc/src/math/generic/nanf128.cpp
+++ b/libc/src/math/generic/nanf128.cpp
@@ -7,18 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nanf128.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/str_to_float.h"
+#include "src/__support/math/nanf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, nanf128, (const char *arg)) {
- auto result = internal::strtonan<float128>(arg);
- if (result.has_error())
- libc_errno = result.error;
- return result.value;
+ return math::nanf128(arg);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nanf16.cpp b/libc/src/math/generic/nanf16.cpp
index 7b166400601bc..b313a32d2178c 100644
--- a/libc/src/math/generic/nanf16.cpp
+++ b/libc/src/math/generic/nanf16.cpp
@@ -7,18 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nanf16.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/str_to_float.h"
+#include "src/__support/math/nanf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, nanf16, (const char *arg)) {
- auto result = internal::strtonan<float16>(arg);
- if (result.has_error())
- libc_errno = result.error;
- return result.value;
+ return math::nanf16(arg);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nanl.cpp b/libc/src/math/generic/nanl.cpp
index 58d638c4b531d..69789a55394e2 100644
--- a/libc/src/math/generic/nanl.cpp
+++ b/libc/src/math/generic/nanl.cpp
@@ -7,18 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nanl.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/str_to_float.h"
+#include "src/__support/math/nanl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, nanl, (const char *arg)) {
- auto result = internal::strtonan<long double>(arg);
- if (result.has_error())
- libc_errno = result.error;
- return result.value;
+ return math::nanl(arg);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index f632843d31284..54c546af2d354 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -278,6 +278,21 @@ add_fp_unittest(
libc.src.__support.math.ilogbf16
libc.src.__support.math.ilogbf128
libc.src.__support.math.ilogbl
+ libc.src.__support.math.iscanonical
+ libc.src.__support.math.iscanonicalbf16
+ libc.src.__support.math.iscanonicalf
+ libc.src.__support.math.iscanonicalf128
+ libc.src.__support.math.iscanonicalf16
+ libc.src.__support.math.iscanonicall
+ libc.src.__support.math.isnan
+ libc.src.__support.math.isnanf
+ libc.src.__support.math.isnanl
+ libc.src.__support.math.issignaling
+ libc.src.__support.math.issignalingbf16
+ libc.src.__support.math.issignalingf
+ libc.src.__support.math.issignalingf128
+ libc.src.__support.math.issignalingf16
+ libc.src.__support.math.issignalingl
libc.src.__support.math.ldexp
libc.src.__support.math.ldexpbf16
libc.src.__support.math.ldexpf
@@ -341,6 +356,12 @@ add_fp_unittest(
libc.src.__support.math.modff128
libc.src.__support.math.modff16
libc.src.__support.math.modfl
+ libc.src.__support.math.nan
+ libc.src.__support.math.nanbf16
+ libc.src.__support.math.nanf
+ libc.src.__support.math.nanf128
+ libc.src.__support.math.nanf16
+ libc.src.__support.math.nanl
libc.src.__support.math.nearbyint
libc.src.__support.math.nearbyintbf16
libc.src.__support.math.nearbyintf
@@ -605,6 +626,21 @@ add_fp_unittest(
libc.src.__support.math.getpayloadf128
libc.src.__support.math.getpayloadf16
libc.src.__support.math.getpayloadl
+ libc.src.__support.math.iscanonical
+ libc.src.__support.math.iscanonicalbf16
+ libc.src.__support.math.iscanonicalf
+ libc.src.__support.math.iscanonicalf128
+ libc.src.__support.math.iscanonicalf16
+ libc.src.__support.math.iscanonicall
+ libc.src.__support.math.isnan
+ libc.src.__support.math.isnanf
+ libc.src.__support.math.isnanl
+ libc.src.__support.math.issignaling
+ libc.src.__support.math.issignalingbf16
+ libc.src.__support.math.issignalingf
+ libc.src.__support.math.issignalingf128
+ libc.src.__support.math.issignalingf16
+ libc.src.__support.math.issignalingl
libc.src.__support.math.ldexp
libc.src.__support.math.ldexpbf16
libc.src.__support.math.ldexpl
@@ -642,6 +678,12 @@ add_fp_unittest(
libc.src.__support.math.modff128
libc.src.__support.math.modff16
libc.src.__support.math.modfl
+ libc.src.__support.math.nan
+ libc.src.__support.math.nanbf16
+ libc.src.__support.math.nanf
+ libc.src.__support.math.nanf128
+ libc.src.__support.math.nanf16
+ libc.src.__support.math.nanl
libc.src.__support.math.nearbyint
libc.src.__support.math.nearbyintbf16
libc.src.__support.math.nearbyintf
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 964c1f9e97f3a..6c57ed3714356 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -72,6 +72,15 @@ static_assert(0L == LIBC_NAMESPACE::shared::lrint(0.0));
static_assert(0L == LIBC_NAMESPACE::shared::lround(0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::nearbyint(0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::rint(0.0));
+static_assert(1 == LIBC_NAMESPACE::shared::iscanonical(0.0));
+static_assert(0.0 == LIBC_NAMESPACE::shared::isnan(0.0));
+static_assert(0.0 == LIBC_NAMESPACE::shared::issignaling(0.0));
+static_assert(1 == [] {
+ const char arg{};
+ return LIBC_NAMESPACE::fputil::FPBits<double>(
+ LIBC_NAMESPACE::shared::nan(&arg))
+ .is_nan();
+}());
//===----------------------------------------------------------------------===//
// Float Tests
@@ -130,6 +139,15 @@ static_assert(0L == LIBC_NAMESPACE::shared::lrintf(0.0f));
static_assert(0L == LIBC_NAMESPACE::shared::lroundf(0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::nearbyintf(0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::rintf(0.0f));
+static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf(0.0f));
+static_assert(0.0 == LIBC_NAMESPACE::shared::isnanf(0.0f));
+static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf(0.0f));
+static_assert(1 == [] {
+ const char arg{};
+ return LIBC_NAMESPACE::fputil::FPBits<float>(
+ LIBC_NAMESPACE::shared::nanf(&arg))
+ .is_nan();
+}());
//===----------------------------------------------------------------------===//
// Float16 Tests
@@ -206,6 +224,14 @@ static_assert(0L == LIBC_NAMESPACE::shared::lrintf16(0.0f16));
static_assert(0L == LIBC_NAMESPACE::shared::lroundf16(0.0f16));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::nearbyintf16(0.0f16));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::rintf16(0.0f16));
+static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf16(0.0f16));
+static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf16(0.0f16));
+static_assert(1 == [] {
+ const char arg{};
+ return LIBC_NAMESPACE::fputil::FPBits<float16>(
+ LIBC_NAMESPACE::shared::nanf16(&arg))
+ .is_nan();
+}());
#endif // LIBC_TYPES_HAS_FLOAT16
//===----------------------------------------------------------------------===//
@@ -279,6 +305,13 @@ static_assert(0L == LIBC_NAMESPACE::shared::lrintl(0.0L));
static_assert(0L == LIBC_NAMESPACE::shared::lroundl(0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::nearbyintl(0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::rintl(0.0L));
+static_assert(1 == LIBC_NAMESPACE::shared::iscanonicall(0.0L));
+static_assert(0.0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
+static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingl(0.0L));
+static_assert(1 == [] {
+ const char arg{};
+ return LIBC_NAMESPACE::fputil::FPBits<long double>(LIBC_NAMESPACE::shared::nanl(&arg)).is_nan();
+}());
#endif
@@ -387,6 +420,14 @@ static_assert(0L == LIBC_NAMESPACE::shared::lroundf128(float128(0.0)));
static_assert(float128(0.0) ==
LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
static_assert(float128(0.0) == LIBC_NAMESPACE::shared::rintf128(float128(0.0)));
+static_assert(1 == LIBC_NAMESPACE::shared::iscanonicalf128(float128(0.0)));
+static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf128(float128(0.0)));
+static_assert(1 == [] {
+ const char arg{};
+ return LIBC_NAMESPACE::fputil::FPBits<float128>(
+ LIBC_NAMESPACE::shared::nanf128(&arg))
+ .is_nan();
+}());
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -491,5 +532,13 @@ static_assert(0L == LIBC_NAMESPACE::shared::lroundbf16(bfloat16(0.0)));
static_assert(bfloat16(0.0) ==
LIBC_NAMESPACE::shared::nearbyintbf16(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::issignalingbf16(bfloat16(0.0)));
+static_assert(bfloat16(1) == [] {
+ const char arg{};
+ return LIBC_NAMESPACE::fputil::FPBits<bfloat16>(
+ LIBC_NAMESPACE::shared::nanbf16(&arg))
+ .is_nan();
+}());
TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {}
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 53389b27567be..8a195438645e2 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -149,6 +149,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf16(0.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::nearbyintf16(0.0f16));
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::issignalingf16(0.0f16));
+ EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf16("")).is_nan());
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -301,6 +304,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::nearbyintf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::rintf(0.0f));
+ EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicalf(0.0f));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingf(0.0f));
+ EXPECT_EQ(1,
+ LIBC_NAMESPACE::shared::isnanf(LIBC_NAMESPACE::shared::nanf("")));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -429,6 +436,9 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llround(0.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::nearbyint(0.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::rint(0.0));
+ EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonical(0.0L));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignaling(0.0));
+ EXPECT_EQ(1, LIBC_NAMESPACE::shared::isnan(LIBC_NAMESPACE::shared::nan("")));
}
// TODO: Enable the tests when double-double type is supported.
@@ -539,6 +549,10 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundl(0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::nearbyintl(0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::rintl(0.0L));
+ EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicall(0.0L));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingl(0.0L));
+ EXPECT_EQ(1,
+ LIBC_NAMESPACE::shared::isnanl(LIBC_NAMESPACE::shared::nanl("")));
}
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
@@ -708,6 +722,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_FP_EQ(float128(0.0),
LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::rintf128(float128(0.0)));
+ EXPECT_EQ(1, LIBC_NAMESPACE::shared::iscanonicalf128(float128(0.0)));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingf128(float128(0.0)));
+ EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf128("")).is_nan());
}
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -840,4 +857,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(0.0),
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::issignalingbf16(bfloat16(0.0)));
+ EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanbf16("")).is_nan());
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e8a7729634d70..adda7fe5bfdd7 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4820,6 +4820,144 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_iscanonical",
+ hdrs = ["src/__support/math/iscanonical.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_iscanonicalbf16",
+ hdrs = ["src/__support/math/iscanonicalbf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_iscanonicalf",
+ hdrs = ["src/__support/math/iscanonicalf.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_iscanonicalf128",
+ hdrs = ["src/__support/math/iscanonicalf128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_iscanonicalf16",
+ hdrs = ["src/__support/math/iscanonicalf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_iscanonicall",
+ hdrs = ["src/__support/math/iscanonicall.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_isnan",
+ hdrs = ["src/__support/math/isnan.h"],
+ deps = [
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_isnanf",
+ hdrs = ["src/__support/math/isnanf.h"],
+ deps = [
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_isnanl",
+ hdrs = ["src/__support/math/isnanl.h"],
+ deps = [
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_issignaling",
+ hdrs = ["src/__support/math/issignaling.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_issignalingbf16",
+ hdrs = ["src/__support/math/issignalingbf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_issignalingf",
+ hdrs = ["src/__support/math/issignalingf.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_issignalingf128",
+ hdrs = ["src/__support/math/issignalingf128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_issignalingf16",
+ hdrs = ["src/__support/math/issignalingf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_issignalingl",
+ hdrs = ["src/__support/math/issignalingl.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_ldexp",
hdrs = ["src/__support/math/ldexp.h"],
@@ -5143,6 +5281,69 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_nan",
+ hdrs = ["src/__support/math/nan.h"],
+ deps = [
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_str_to_float",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nanbf16",
+ hdrs = ["src/__support/math/nanbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_str_to_float",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nanf",
+ hdrs = ["src/__support/math/nanf.h"],
+ deps = [
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_str_to_float",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nanf128",
+ hdrs = ["src/__support/math/nanf128.h"],
+ deps = [
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_str_to_float",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nanf16",
+ hdrs = ["src/__support/math/nanf16.h"],
+ deps = [
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_str_to_float",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nanl",
+ hdrs = ["src/__support/math/nanl.h"],
+ deps = [
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_str_to_float",
+ ],
+)
+
libc_support_library(
name = "__support_math_nearbyint",
hdrs = ["src/__support/math/nearbyint.h"],
@@ -9078,32 +9279,109 @@ libc_math_function(
],
)
-libc_math_function(name = "iscanonical")
+libc_math_function(
+ name = "iscanonical",
+ additional_deps = [
+ ":__support_math_iscanonical",
+ ],
+)
-libc_math_function(name = "iscanonicalf")
+libc_math_function(
+ name = "iscanonicalbf16",
+ additional_deps = [
+ ":__support_math_iscanonicalbf16",
+ ],
+)
+
+libc_math_function(
+ name = "iscanonicalf",
+ additional_deps = [
+ ":__support_math_iscanonicalf",
+ ],
+)
-libc_math_function(name = "iscanonicall")
+libc_math_function(
+ name = "iscanonicall",
+ additional_deps = [
+ ":__support_math_iscanonicall",
+ ],
+)
libc_math_function(
name = "iscanonicalf128",
+ additional_deps = [
+ ":__support_math_iscanonicalf128",
+ ],
)
libc_math_function(
name = "iscanonicalf16",
+ additional_deps = [
+ ":__support_math_iscanonicalf16",
+ ],
+)
+
+libc_math_function(
+ name = "isnan",
+ additional_deps = [
+ ":__support_math_isnan",
+ ],
+)
+
+libc_math_function(
+ name = "isnanf",
+ additional_deps = [
+ ":__support_math_isnanf",
+ ],
+)
+
+libc_math_function(
+ name = "isnanl",
+ additional_deps = [
+ ":__support_math_isnanl",
+ ],
)
-libc_math_function(name = "issignaling")
+libc_math_function(
+ name = "issignaling",
+ additional_deps = [
+ ":__support_math_issignaling",
+ ],
+)
-libc_math_function(name = "issignalingf")
+libc_math_function(
+ name = "issignalingbf16",
+ additional_deps = [
+ ":__support_math_issignalingbf16",
+ ],
+)
-libc_math_function(name = "issignalingl")
+libc_math_function(
+ name = "issignalingf",
+ additional_deps = [
+ ":__support_math_issignalingf",
+ ],
+)
+
+libc_math_function(
+ name = "issignalingl",
+ additional_deps = [
+ ":__support_math_issignalingl",
+ ],
+)
libc_math_function(
name = "issignalingf128",
+ additional_deps = [
+ ":__support_math_issignalingf128",
+ ],
)
libc_math_function(
name = "issignalingf16",
+ additional_deps = [
+ ":__support_math_issignalingf16",
+ ],
)
libc_math_function(
@@ -10911,45 +11189,42 @@ libc_math_function(
libc_math_function(
name = "nan",
additional_deps = [
- ":__support_libc_errno",
- ":__support_str_to_float",
- ":errno",
+ ":__support_math_nan",
+ ],
+)
+
+libc_math_function(
+ name = "nanbf16",
+ additional_deps = [
+ ":__support_math_nanbf16",
],
)
libc_math_function(
name = "nanf",
additional_deps = [
- ":__support_libc_errno",
- ":__support_str_to_float",
- ":errno",
+ ":__support_math_nanf",
],
)
libc_math_function(
name = "nanl",
additional_deps = [
- ":__support_libc_errno",
- ":__support_str_to_float",
- ":errno",
+ ":__support_math_nanl",
],
)
libc_math_function(
name = "nanf128",
additional_deps = [
- ":__support_libc_errno",
- ":__support_str_to_float",
- ":errno",
+ ":__support_math_nanf128",
],
)
libc_math_function(
name = "nanf16",
additional_deps = [
- ":__support_libc_errno",
- ":__support_str_to_float",
- ":errno",
+ ":__support_math_nanf16",
],
)
>From 7a1149cd887756e36b6612186433f413833e4460 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Mon, 4 May 2026 07:43:13 +0300
Subject: [PATCH 2/3] fix constexpr steps
---
libc/test/shared/CMakeLists.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 54c546af2d354..40c65aa7f0768 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -745,6 +745,9 @@ add_fp_unittest(
libc.src.__support.math.totalordermagf128
libc.src.__support.math.totalordermagf16
libc.src.__support.math.totalordermagl
+ COMPILE_OPTIONS
+ $<$<CXX_COMPILER_ID:Clang>:-Xclang -fconstexpr-steps=1000>
+ $<$<CXX_COMPILER_ID:GNU>:-fconstexpr-depth=1000>
)
add_fp_unittest(
>From 106b0445c334802ca91481b9e4a05fd7cceea1db Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Mon, 4 May 2026 07:50:46 +0300
Subject: [PATCH 3/3] modify flag
---
libc/test/shared/CMakeLists.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 40c65aa7f0768..87231171d8b7d 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -746,8 +746,8 @@ add_fp_unittest(
libc.src.__support.math.totalordermagf16
libc.src.__support.math.totalordermagl
COMPILE_OPTIONS
- $<$<CXX_COMPILER_ID:Clang>:-Xclang -fconstexpr-steps=1000>
- $<$<CXX_COMPILER_ID:GNU>:-fconstexpr-depth=1000>
+ $<$<CXX_COMPILER_ID:Clang>:-Xclang -fconstexpr-depth=100>
+ $<$<CXX_COMPILER_ID:GNU>:-fconstexpr-depth=100>
)
add_fp_unittest(
More information about the libc-commits
mailing list