diff --git a/libcxx/include/math.h b/libcxx/include/math.h index fdf3231c2978c..b068ea388f095 100644 --- a/libcxx/include/math.h +++ b/libcxx/include/math.h @@ -387,8 +387,19 @@ namespace __math { // fpclassify -template ::value, int> = 0> -_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT { +// template on non-double overloads to make them weaker than same overloads from MSVC runtime +template +_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 +_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); +} + +template +_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); } diff --git a/libcxx/test/std/numerics/c.math/cmath.pass.cpp b/libcxx/test/std/numerics/c.math/cmath.pass.cpp index e2062cc7ecfd9..11a3de748cb7a 100644 --- a/libcxx/test/std/numerics/c.math/cmath.pass.cpp +++ b/libcxx/test/std/numerics/c.math/cmath.pass.cpp @@ -603,12 +603,20 @@ void test_fpclassify() static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); + static_assert((std::is_same())), int>::value), ""); + static_assert((std::is_same())), int>::value), ""); + static_assert((std::is_same())), int>::value), ""); + ASSERT_NOEXCEPT(std::fpclassify((float)0)); + ASSERT_NOEXCEPT(std::fpclassify((double)0)); + ASSERT_NOEXCEPT(std::fpclassify((long double)0)); + ASSERT_NOEXCEPT(std::fpclassify(0)); assert(std::fpclassify(-1.0) == FP_NORMAL); assert(std::fpclassify(0) == FP_ZERO); assert(std::fpclassify(1) == FP_NORMAL); assert(std::fpclassify(-1) == FP_NORMAL); assert(std::fpclassify(std::numeric_limits::max()) == FP_NORMAL); assert(std::fpclassify(std::numeric_limits::min()) == FP_NORMAL); + assert(std::fpclassify(Value()) == FP_NORMAL); } void test_isfinite()