[libcxx-commits] [libcxx] [libc++] Add std::fpclassify overloads for floating-point. (PR #67913)

Anatolii Malibroda via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 1 06:01:28 PDT 2023


https://github.com/antl-m created https://github.com/llvm/llvm-project/pull/67913

Standard says that implementation of math functions that have floating-point-type parameter should provide an "overload for each cv-unqualified floating-point type".


>From 32992d2e4cccf8b3a604d921815675af9bb36346 Mon Sep 17 00:00:00 2001
From: Anatolii Malibroda <tolikmalibroda at gmail.com>
Date: Sun, 1 Oct 2023 14:54:42 +0200
Subject: [PATCH] [libc++] Add std::fpclassify overloads for floating-point.

Standard says that implementation of math functions that have floating-point-type parameter should provide an "overload for each cv-unqualified floating-point type".
---
 libcxx/include/math.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index fdf3231c2978cee..59787fb8408b167 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -387,8 +387,16 @@ namespace __math {
 
 // fpclassify
 
-template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
+  return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
+}
+
+template <class = int>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(double __x) _NOEXCEPT {
+  return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
+}
+
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(long double __x) _NOEXCEPT {
   return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
 }
 



More information about the libcxx-commits mailing list