Skip to content

[libc++][NFC] Remove __constexpr_is{nan,finite} #106205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions libcxx/include/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -554,20 +554,6 @@ using ::scalbnl _LIBCPP_USING_IF_EXISTS;
using ::tgammal _LIBCPP_USING_IF_EXISTS;
using ::truncl _LIBCPP_USING_IF_EXISTS;

template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT {
#if __has_builtin(__builtin_isnan)
return __builtin_isnan(__lcpp_x);
#else
return isnan(__lcpp_x);
#endif
}

template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT {
return std::isnan(__lcpp_x);
}

template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, most uses of __constexpr_isinf can also be replaced with std::isinf except for the ones in std::norm. I guess we can move __constexpr_isinf to <complex>.

template <class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp norm(const complex<_Tp>& __c) {
if (std::__constexpr_isinf(__c.real()))
return std::abs(__c.real());
if (std::__constexpr_isinf(__c.imag()))
return std::abs(__c.imag());
return __c.real() * __c.real() + __c.imag() * __c.imag();
}

#if __has_builtin(__builtin_isinf)
Expand All @@ -582,20 +568,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NO
return std::isinf(__lcpp_x);
}

template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT {
#if __has_builtin(__builtin_isfinite)
return __builtin_isfinite(__lcpp_x);
#else
return isfinite(__lcpp_x);
#endif
}

template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT {
return __builtin_isfinite(__lcpp_x);
}

#if _LIBCPP_STD_VER >= 20
template <typename _Fp>
_LIBCPP_HIDE_FROM_ABI constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
Expand Down
50 changes: 24 additions & 26 deletions libcxx/include/complex
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,9 @@ inline _LIBCPP_HIDE_FROM_ABI typename __libcpp_complex_overload_traits<_Tp>::_Co

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta = _Tp()) {
if (std::__constexpr_isnan(__rho) || std::signbit(__rho))
if (std::isnan(__rho) || std::signbit(__rho))
return complex<_Tp>(_Tp(NAN), _Tp(NAN));
if (std::__constexpr_isnan(__theta)) {
if (std::isnan(__theta)) {
if (std::__constexpr_isinf(__rho))
return complex<_Tp>(__rho, __theta);
return complex<_Tp>(__theta, __theta);
Expand All @@ -1032,10 +1032,10 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta =
return complex<_Tp>(_Tp(NAN), _Tp(NAN));
}
_Tp __x = __rho * std::cos(__theta);
if (std::__constexpr_isnan(__x))
if (std::isnan(__x))
__x = 0;
_Tp __y = __rho * std::sin(__theta);
if (std::__constexpr_isnan(__y))
if (std::isnan(__y))
__y = 0;
return complex<_Tp>(__x, __y);
}
Expand All @@ -1062,10 +1062,8 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> sqrt(const complex<_Tp>& __x) {
return complex<_Tp>(_Tp(INFINITY), __x.imag());
if (std::__constexpr_isinf(__x.real())) {
if (__x.real() > _Tp(0))
return complex<_Tp>(
__x.real(), std::__constexpr_isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
return complex<_Tp>(
std::__constexpr_isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
return complex<_Tp>(__x.real(), std::isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
return complex<_Tp>(std::isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
}
return std::polar(std::sqrt(std::abs(__x)), std::arg(__x) / _Tp(2));
}
Expand All @@ -1080,9 +1078,9 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> exp(const complex<_Tp>& __x) {
}
if (std::__constexpr_isinf(__x.real())) {
if (__x.real() < _Tp(0)) {
if (!std::__constexpr_isfinite(__i))
if (!std::isfinite(__i))
__i = _Tp(1);
} else if (__i == 0 || !std::__constexpr_isfinite(__i)) {
} else if (__i == 0 || !std::isfinite(__i)) {
if (std::__constexpr_isinf(__i))
__i = _Tp(NAN);
return complex<_Tp>(__x.real(), __i);
Expand Down Expand Up @@ -1131,13 +1129,13 @@ template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> asinh(const complex<_Tp>& __x) {
const _Tp __pi(atan2(+0., -0.));
if (std::__constexpr_isinf(__x.real())) {
if (std::__constexpr_isnan(__x.imag()))
if (std::isnan(__x.imag()))
return __x;
if (std::__constexpr_isinf(__x.imag()))
return complex<_Tp>(__x.real(), std::copysign(__pi * _Tp(0.25), __x.imag()));
return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
}
if (std::__constexpr_isnan(__x.real())) {
if (std::isnan(__x.real())) {
if (std::__constexpr_isinf(__x.imag()))
return complex<_Tp>(__x.imag(), __x.real());
if (__x.imag() == 0)
Expand All @@ -1156,7 +1154,7 @@ template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
const _Tp __pi(atan2(+0., -0.));
if (std::__constexpr_isinf(__x.real())) {
if (std::__constexpr_isnan(__x.imag()))
if (std::isnan(__x.imag()))
return complex<_Tp>(std::abs(__x.real()), __x.imag());
if (std::__constexpr_isinf(__x.imag())) {
if (__x.real() > 0)
Expand All @@ -1168,7 +1166,7 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
return complex<_Tp>(-__x.real(), std::copysign(__pi, __x.imag()));
return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
}
if (std::__constexpr_isnan(__x.real())) {
if (std::isnan(__x.real())) {
if (std::__constexpr_isinf(__x.imag()))
return complex<_Tp>(std::abs(__x.imag()), __x.real());
return complex<_Tp>(__x.real(), __x.real());
Expand All @@ -1187,12 +1185,12 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> atanh(const complex<_Tp>& __x) {
if (std::__constexpr_isinf(__x.imag())) {
return complex<_Tp>(std::copysign(_Tp(0), __x.real()), std::copysign(__pi / _Tp(2), __x.imag()));
}
if (std::__constexpr_isnan(__x.imag())) {
if (std::isnan(__x.imag())) {
if (std::__constexpr_isinf(__x.real()) || __x.real() == 0)
return complex<_Tp>(std::copysign(_Tp(0), __x.real()), __x.imag());
return complex<_Tp>(__x.imag(), __x.imag());
}
if (std::__constexpr_isnan(__x.real())) {
if (std::isnan(__x.real())) {
return complex<_Tp>(__x.real(), __x.real());
}
if (std::__constexpr_isinf(__x.real())) {
Expand All @@ -1209,11 +1207,11 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> atanh(const complex<_Tp>& __x) {

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> sinh(const complex<_Tp>& __x) {
if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
if (std::__constexpr_isinf(__x.real()) && !std::isfinite(__x.imag()))
return complex<_Tp>(__x.real(), _Tp(NAN));
if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
if (__x.real() == 0 && !std::isfinite(__x.imag()))
return complex<_Tp>(__x.real(), _Tp(NAN));
if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
if (__x.imag() == 0 && !std::isfinite(__x.real()))
return __x;
return complex<_Tp>(std::sinh(__x.real()) * std::cos(__x.imag()), std::cosh(__x.real()) * std::sin(__x.imag()));
}
Expand All @@ -1222,13 +1220,13 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> sinh(const complex<_Tp>& __x) {

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> cosh(const complex<_Tp>& __x) {
if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
if (std::__constexpr_isinf(__x.real()) && !std::isfinite(__x.imag()))
return complex<_Tp>(std::abs(__x.real()), _Tp(NAN));
if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
if (__x.real() == 0 && !std::isfinite(__x.imag()))
return complex<_Tp>(_Tp(NAN), __x.real());
if (__x.real() == 0 && __x.imag() == 0)
return complex<_Tp>(_Tp(1), __x.imag());
if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
if (__x.imag() == 0 && !std::isfinite(__x.real()))
return complex<_Tp>(std::abs(__x.real()), __x.imag());
return complex<_Tp>(std::cosh(__x.real()) * std::cos(__x.imag()), std::sinh(__x.real()) * std::sin(__x.imag()));
}
Expand All @@ -1238,11 +1236,11 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> cosh(const complex<_Tp>& __x) {
template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> tanh(const complex<_Tp>& __x) {
if (std::__constexpr_isinf(__x.real())) {
if (!std::__constexpr_isfinite(__x.imag()))
if (!std::isfinite(__x.imag()))
return complex<_Tp>(std::copysign(_Tp(1), __x.real()), _Tp(0));
return complex<_Tp>(std::copysign(_Tp(1), __x.real()), std::copysign(_Tp(0), std::sin(_Tp(2) * __x.imag())));
}
if (std::__constexpr_isnan(__x.real()) && __x.imag() == 0)
if (std::isnan(__x.real()) && __x.imag() == 0)
return __x;
_Tp __2r(_Tp(2) * __x.real());
_Tp __2i(_Tp(2) * __x.imag());
Expand All @@ -1267,7 +1265,7 @@ template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> acos(const complex<_Tp>& __x) {
const _Tp __pi(atan2(+0., -0.));
if (std::__constexpr_isinf(__x.real())) {
if (std::__constexpr_isnan(__x.imag()))
if (std::isnan(__x.imag()))
return complex<_Tp>(__x.imag(), __x.real());
if (std::__constexpr_isinf(__x.imag())) {
if (__x.real() < _Tp(0))
Expand All @@ -1278,7 +1276,7 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acos(const complex<_Tp>& __x) {
return complex<_Tp>(__pi, std::signbit(__x.imag()) ? -__x.real() : __x.real());
return complex<_Tp>(_Tp(0), std::signbit(__x.imag()) ? __x.real() : -__x.real());
}
if (std::__constexpr_isnan(__x.real())) {
if (std::isnan(__x.real())) {
if (std::__constexpr_isinf(__x.imag()))
return complex<_Tp>(__x.real(), -__x.imag());
return complex<_Tp>(__x.real(), __x.real());
Expand Down
2 changes: 0 additions & 2 deletions libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

#include "test_macros.h"

static_assert(std::__constexpr_isnan(0.) == false, "");
static_assert(std::__constexpr_isinf(0.0) == false, "");
static_assert(std::__constexpr_isfinite(0.0) == true, "");

int main(int, char**)
{
Expand Down
Loading