Skip to content

Commit a705e8c

Browse files
authored
[libc++][NFC] Remove __constexpr_is{nan,finite} (#106205)
They're never used in `constexpr` functions, so we can simply use `std::isnan` and `std::isfinite` instead.
1 parent 025f03f commit a705e8c

File tree

3 files changed

+24
-56
lines changed

3 files changed

+24
-56
lines changed

libcxx/include/cmath

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -554,20 +554,6 @@ using ::scalbnl _LIBCPP_USING_IF_EXISTS;
554554
using ::tgammal _LIBCPP_USING_IF_EXISTS;
555555
using ::truncl _LIBCPP_USING_IF_EXISTS;
556556

557-
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
558-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT {
559-
#if __has_builtin(__builtin_isnan)
560-
return __builtin_isnan(__lcpp_x);
561-
#else
562-
return isnan(__lcpp_x);
563-
#endif
564-
}
565-
566-
template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
567-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT {
568-
return std::isnan(__lcpp_x);
569-
}
570-
571557
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
572558
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT {
573559
#if __has_builtin(__builtin_isinf)
@@ -582,20 +568,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NO
582568
return std::isinf(__lcpp_x);
583569
}
584570

585-
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
586-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT {
587-
#if __has_builtin(__builtin_isfinite)
588-
return __builtin_isfinite(__lcpp_x);
589-
#else
590-
return isfinite(__lcpp_x);
591-
#endif
592-
}
593-
594-
template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
595-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT {
596-
return __builtin_isfinite(__lcpp_x);
597-
}
598-
599571
#if _LIBCPP_STD_VER >= 20
600572
template <typename _Fp>
601573
_LIBCPP_HIDE_FROM_ABI constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {

libcxx/include/complex

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,9 @@ inline _LIBCPP_HIDE_FROM_ABI typename __libcpp_complex_overload_traits<_Tp>::_Co
10191019

10201020
template <class _Tp>
10211021
_LIBCPP_HIDE_FROM_ABI complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta = _Tp()) {
1022-
if (std::__constexpr_isnan(__rho) || std::signbit(__rho))
1022+
if (std::isnan(__rho) || std::signbit(__rho))
10231023
return complex<_Tp>(_Tp(NAN), _Tp(NAN));
1024-
if (std::__constexpr_isnan(__theta)) {
1024+
if (std::isnan(__theta)) {
10251025
if (std::__constexpr_isinf(__rho))
10261026
return complex<_Tp>(__rho, __theta);
10271027
return complex<_Tp>(__theta, __theta);
@@ -1032,10 +1032,10 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta =
10321032
return complex<_Tp>(_Tp(NAN), _Tp(NAN));
10331033
}
10341034
_Tp __x = __rho * std::cos(__theta);
1035-
if (std::__constexpr_isnan(__x))
1035+
if (std::isnan(__x))
10361036
__x = 0;
10371037
_Tp __y = __rho * std::sin(__theta);
1038-
if (std::__constexpr_isnan(__y))
1038+
if (std::isnan(__y))
10391039
__y = 0;
10401040
return complex<_Tp>(__x, __y);
10411041
}
@@ -1062,10 +1062,8 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> sqrt(const complex<_Tp>& __x) {
10621062
return complex<_Tp>(_Tp(INFINITY), __x.imag());
10631063
if (std::__constexpr_isinf(__x.real())) {
10641064
if (__x.real() > _Tp(0))
1065-
return complex<_Tp>(
1066-
__x.real(), std::__constexpr_isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
1067-
return complex<_Tp>(
1068-
std::__constexpr_isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
1065+
return complex<_Tp>(__x.real(), std::isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
1066+
return complex<_Tp>(std::isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
10691067
}
10701068
return std::polar(std::sqrt(std::abs(__x)), std::arg(__x) / _Tp(2));
10711069
}
@@ -1080,9 +1078,9 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> exp(const complex<_Tp>& __x) {
10801078
}
10811079
if (std::__constexpr_isinf(__x.real())) {
10821080
if (__x.real() < _Tp(0)) {
1083-
if (!std::__constexpr_isfinite(__i))
1081+
if (!std::isfinite(__i))
10841082
__i = _Tp(1);
1085-
} else if (__i == 0 || !std::__constexpr_isfinite(__i)) {
1083+
} else if (__i == 0 || !std::isfinite(__i)) {
10861084
if (std::__constexpr_isinf(__i))
10871085
__i = _Tp(NAN);
10881086
return complex<_Tp>(__x.real(), __i);
@@ -1131,13 +1129,13 @@ template <class _Tp>
11311129
_LIBCPP_HIDE_FROM_ABI complex<_Tp> asinh(const complex<_Tp>& __x) {
11321130
const _Tp __pi(atan2(+0., -0.));
11331131
if (std::__constexpr_isinf(__x.real())) {
1134-
if (std::__constexpr_isnan(__x.imag()))
1132+
if (std::isnan(__x.imag()))
11351133
return __x;
11361134
if (std::__constexpr_isinf(__x.imag()))
11371135
return complex<_Tp>(__x.real(), std::copysign(__pi * _Tp(0.25), __x.imag()));
11381136
return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
11391137
}
1140-
if (std::__constexpr_isnan(__x.real())) {
1138+
if (std::isnan(__x.real())) {
11411139
if (std::__constexpr_isinf(__x.imag()))
11421140
return complex<_Tp>(__x.imag(), __x.real());
11431141
if (__x.imag() == 0)
@@ -1156,7 +1154,7 @@ template <class _Tp>
11561154
_LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
11571155
const _Tp __pi(atan2(+0., -0.));
11581156
if (std::__constexpr_isinf(__x.real())) {
1159-
if (std::__constexpr_isnan(__x.imag()))
1157+
if (std::isnan(__x.imag()))
11601158
return complex<_Tp>(std::abs(__x.real()), __x.imag());
11611159
if (std::__constexpr_isinf(__x.imag())) {
11621160
if (__x.real() > 0)
@@ -1168,7 +1166,7 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
11681166
return complex<_Tp>(-__x.real(), std::copysign(__pi, __x.imag()));
11691167
return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
11701168
}
1171-
if (std::__constexpr_isnan(__x.real())) {
1169+
if (std::isnan(__x.real())) {
11721170
if (std::__constexpr_isinf(__x.imag()))
11731171
return complex<_Tp>(std::abs(__x.imag()), __x.real());
11741172
return complex<_Tp>(__x.real(), __x.real());
@@ -1187,12 +1185,12 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> atanh(const complex<_Tp>& __x) {
11871185
if (std::__constexpr_isinf(__x.imag())) {
11881186
return complex<_Tp>(std::copysign(_Tp(0), __x.real()), std::copysign(__pi / _Tp(2), __x.imag()));
11891187
}
1190-
if (std::__constexpr_isnan(__x.imag())) {
1188+
if (std::isnan(__x.imag())) {
11911189
if (std::__constexpr_isinf(__x.real()) || __x.real() == 0)
11921190
return complex<_Tp>(std::copysign(_Tp(0), __x.real()), __x.imag());
11931191
return complex<_Tp>(__x.imag(), __x.imag());
11941192
}
1195-
if (std::__constexpr_isnan(__x.real())) {
1193+
if (std::isnan(__x.real())) {
11961194
return complex<_Tp>(__x.real(), __x.real());
11971195
}
11981196
if (std::__constexpr_isinf(__x.real())) {
@@ -1209,11 +1207,11 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> atanh(const complex<_Tp>& __x) {
12091207

12101208
template <class _Tp>
12111209
_LIBCPP_HIDE_FROM_ABI complex<_Tp> sinh(const complex<_Tp>& __x) {
1212-
if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
1210+
if (std::__constexpr_isinf(__x.real()) && !std::isfinite(__x.imag()))
12131211
return complex<_Tp>(__x.real(), _Tp(NAN));
1214-
if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
1212+
if (__x.real() == 0 && !std::isfinite(__x.imag()))
12151213
return complex<_Tp>(__x.real(), _Tp(NAN));
1216-
if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
1214+
if (__x.imag() == 0 && !std::isfinite(__x.real()))
12171215
return __x;
12181216
return complex<_Tp>(std::sinh(__x.real()) * std::cos(__x.imag()), std::cosh(__x.real()) * std::sin(__x.imag()));
12191217
}
@@ -1222,13 +1220,13 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> sinh(const complex<_Tp>& __x) {
12221220

12231221
template <class _Tp>
12241222
_LIBCPP_HIDE_FROM_ABI complex<_Tp> cosh(const complex<_Tp>& __x) {
1225-
if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
1223+
if (std::__constexpr_isinf(__x.real()) && !std::isfinite(__x.imag()))
12261224
return complex<_Tp>(std::abs(__x.real()), _Tp(NAN));
1227-
if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
1225+
if (__x.real() == 0 && !std::isfinite(__x.imag()))
12281226
return complex<_Tp>(_Tp(NAN), __x.real());
12291227
if (__x.real() == 0 && __x.imag() == 0)
12301228
return complex<_Tp>(_Tp(1), __x.imag());
1231-
if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
1229+
if (__x.imag() == 0 && !std::isfinite(__x.real()))
12321230
return complex<_Tp>(std::abs(__x.real()), __x.imag());
12331231
return complex<_Tp>(std::cosh(__x.real()) * std::cos(__x.imag()), std::sinh(__x.real()) * std::sin(__x.imag()));
12341232
}
@@ -1238,11 +1236,11 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> cosh(const complex<_Tp>& __x) {
12381236
template <class _Tp>
12391237
_LIBCPP_HIDE_FROM_ABI complex<_Tp> tanh(const complex<_Tp>& __x) {
12401238
if (std::__constexpr_isinf(__x.real())) {
1241-
if (!std::__constexpr_isfinite(__x.imag()))
1239+
if (!std::isfinite(__x.imag()))
12421240
return complex<_Tp>(std::copysign(_Tp(1), __x.real()), _Tp(0));
12431241
return complex<_Tp>(std::copysign(_Tp(1), __x.real()), std::copysign(_Tp(0), std::sin(_Tp(2) * __x.imag())));
12441242
}
1245-
if (std::__constexpr_isnan(__x.real()) && __x.imag() == 0)
1243+
if (std::isnan(__x.real()) && __x.imag() == 0)
12461244
return __x;
12471245
_Tp __2r(_Tp(2) * __x.real());
12481246
_Tp __2i(_Tp(2) * __x.imag());
@@ -1267,7 +1265,7 @@ template <class _Tp>
12671265
_LIBCPP_HIDE_FROM_ABI complex<_Tp> acos(const complex<_Tp>& __x) {
12681266
const _Tp __pi(atan2(+0., -0.));
12691267
if (std::__constexpr_isinf(__x.real())) {
1270-
if (std::__constexpr_isnan(__x.imag()))
1268+
if (std::isnan(__x.imag()))
12711269
return complex<_Tp>(__x.imag(), __x.real());
12721270
if (std::__constexpr_isinf(__x.imag())) {
12731271
if (__x.real() < _Tp(0))
@@ -1278,7 +1276,7 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acos(const complex<_Tp>& __x) {
12781276
return complex<_Tp>(__pi, std::signbit(__x.imag()) ? -__x.real() : __x.real());
12791277
return complex<_Tp>(_Tp(0), std::signbit(__x.imag()) ? __x.real() : -__x.real());
12801278
}
1281-
if (std::__constexpr_isnan(__x.real())) {
1279+
if (std::isnan(__x.real())) {
12821280
if (std::__constexpr_isinf(__x.imag()))
12831281
return complex<_Tp>(__x.real(), -__x.imag());
12841282
return complex<_Tp>(__x.real(), __x.real());

libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
#include "test_macros.h"
2222

23-
static_assert(std::__constexpr_isnan(0.) == false, "");
2423
static_assert(std::__constexpr_isinf(0.0) == false, "");
25-
static_assert(std::__constexpr_isfinite(0.0) == true, "");
2624

2725
int main(int, char**)
2826
{

0 commit comments

Comments
 (0)