From ba1e13d5245977686d37b81ed31ad07a58e35721 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 4 Nov 2022 20:19:20 +0100 Subject: [PATCH] [libc++][math.h] move #undefs to the top and guard explicitly against MSVCRT instead Reviewed By: ldionne, #libc Spies: #libc_vendors, EricWF, libcxx-commits Differential Revision: https://reviews.llvm.org/D137502 --- libcxx/include/math.h | 106 ++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/libcxx/include/math.h b/libcxx/include/math.h index 839be4d11f6b..b3990f314046 100644 --- a/libcxx/include/math.h +++ b/libcxx/include/math.h @@ -312,11 +312,56 @@ extern "C++" { #include #include -// signbit + +# ifdef fpclassify +# undef fpclassify +# endif # ifdef signbit # undef signbit -# endif // signbit +# endif + +# ifdef isfinite +# undef isfinite +# endif + +# ifdef isinf +# undef isinf +# endif + +# ifdef isnan +# undef isnan +# endif + +# ifdef isnormal +# undef isnormal +# endif + +# ifdef isgreater +# undef isgreater +# endif + +# ifdef isgreaterequal +# undef isgreaterequal +# endif + +# ifdef isless +# undef isless +# endif + +# ifdef islessequal +# undef islessequal +# endif + +# ifdef islessgreater +# undef islessgreater +# endif + +# ifdef isunordered +# undef isunordered +# endif + +// signbit template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { @@ -335,10 +380,6 @@ inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT { // fpclassify -# ifdef fpclassify -# undef fpclassify -# endif // fpclassify - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x); @@ -349,10 +390,10 @@ inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT { return __x == 0 ? FP_ZERO : FP_NORMAL; } -// isfinite +// The MSVC runtime already provides these functions as templates +#ifndef _LIBCPP_MSVCRT -# ifdef isfinite -# undef isfinite +// isfinite template ::value && std::numeric_limits<_A1>::has_infinity, int> = 0> @@ -366,13 +407,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT { return true; } -# endif // isfinite - // isinf -# ifdef isinf -# undef isinf - template ::value && std::numeric_limits<_A1>::has_infinity, int> = 0> inline _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT { @@ -394,13 +430,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _ inline _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __builtin_isinf(__x); } # endif -# endif // isinf - // isnan -# ifdef isnan -# undef isnan - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT { return __builtin_isnan(__x); @@ -419,13 +450,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _ inline _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __builtin_isnan(__x); } # endif -# endif // isnan - // isnormal -# ifdef isnormal -# undef isnormal - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { return __builtin_isnormal(__x); @@ -436,13 +462,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { return __x != 0; } -# endif // isnormal - // isgreater -# ifdef isgreater -# undef isgreater - template ::value && std::is_arithmetic<_A2>::value, int> = 0> @@ -451,13 +472,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT { return __builtin_isgreater((type)__x, (type)__y); } -# endif // isgreater - // isgreaterequal -# ifdef isgreaterequal -# undef isgreaterequal - template ::value && std::is_arithmetic<_A2>::value, int> = 0> @@ -466,13 +482,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT { return __builtin_isgreaterequal((type)__x, (type)__y); } -# endif // isgreaterequal - // isless -# ifdef isless -# undef isless - template ::value && std::is_arithmetic<_A2>::value, int> = 0> @@ -481,13 +492,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT { return __builtin_isless((type)__x, (type)__y); } -# endif // isless - // islessequal -# ifdef islessequal -# undef islessequal - template ::value && std::is_arithmetic<_A2>::value, int> = 0> @@ -496,13 +502,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT { return __builtin_islessequal((type)__x, (type)__y); } -# endif // islessequal - // islessgreater -# ifdef islessgreater -# undef islessgreater - template ::value && std::is_arithmetic<_A2>::value, int> = 0> @@ -511,13 +512,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT { return __builtin_islessgreater((type)__x, (type)__y); } -# endif // islessgreater - // isunordered -# ifdef isunordered -# undef isunordered - template ::value && std::is_arithmetic<_A2>::value, int> = 0> @@ -526,7 +522,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT { return __builtin_isunordered((type)__x, (type)__y); } -# endif // isunordered +#endif // _LIBCPP_MSVCRT // abs //