Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/math.h
Show First 20 Lines • Show All 293 Lines • ▼ Show 20 Lines | |||||
#include <__config> | #include <__config> | ||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||||
# pragma GCC system_header | # pragma GCC system_header | ||||
#endif | #endif | ||||
#include_next <math.h> | #include_next <math.h> | ||||
#ifdef __cplusplus | #ifdef isless | ||||
# undef isless | |||||
// We support including .h headers inside 'extern "C"' contexts, so switch | #endif | ||||
// back to C++ linkage before including these C++ headers. | |||||
extern "C++" { | |||||
#include <__type_traits/promote.h> | #ifdef islessequal | ||||
#include <limits> | # undef islessequal | ||||
#include <stdlib.h> | #endif | ||||
#include <type_traits> | |||||
// signbit | #ifdef islessgreater | ||||
# undef islessgreater | |||||
#endif | |||||
#ifdef signbit | #ifdef isgreaterequal | ||||
# undef isgreaterequal | |||||
#endif | |||||
template <class _A1> | #ifdef isgreater | ||||
_LIBCPP_INLINE_VISIBILITY | # undef isgreater | ||||
bool | |||||
__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
#if __has_builtin(__builtin_signbit) | |||||
return __builtin_signbit(__lcpp_x); | |||||
#else | |||||
return signbit(__lcpp_x); | |||||
#endif | #endif | ||||
} | |||||
#undef signbit | #ifdef isunordered | ||||
# undef isunordered | |||||
#endif | |||||
template <class _A1> | #ifdef isfinite | ||||
inline _LIBCPP_INLINE_VISIBILITY | # undef isfinite | ||||
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type | #endif | ||||
signbit(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x); | |||||
} | |||||
template <class _A1> | #ifdef isinf | ||||
inline _LIBCPP_INLINE_VISIBILITY | # undef isinf | ||||
typename std::enable_if< | #endif | ||||
std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type | |||||
signbit(_A1 __lcpp_x) _NOEXCEPT | |||||
{ return __lcpp_x < 0; } | |||||
template <class _A1> | #ifdef isnan | ||||
inline _LIBCPP_INLINE_VISIBILITY | # undef isnan | ||||
typename std::enable_if< | #endif | ||||
std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type | |||||
signbit(_A1) _NOEXCEPT | |||||
{ return false; } | |||||
#elif defined(_LIBCPP_MSVCRT) | #ifdef isnormal | ||||
# undef isnormal | |||||
#endif | |||||
template <typename _A1> | #ifdef signbit | ||||
inline _LIBCPP_INLINE_VISIBILITY | # undef signbit | ||||
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type | #endif | ||||
signbit(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
return ::signbit(static_cast<typename std::__promote<_A1>::type>(__lcpp_x)); | |||||
} | |||||
template <class _A1> | #ifdef __cplusplus | ||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if< | |||||
std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type | |||||
signbit(_A1 __lcpp_x) _NOEXCEPT | |||||
{ return __lcpp_x < 0; } | |||||
template <class _A1> | // We support including .h headers inside 'extern "C"' contexts, so switch | ||||
inline _LIBCPP_INLINE_VISIBILITY | // back to C++ linkage before including these C++ headers. | ||||
typename std::enable_if< | extern "C++" { | ||||
std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type | #include <__cmath/compare.h> | ||||
signbit(_A1) _NOEXCEPT | #include <__cmath/isfinite.h> | ||||
{ return false; } | #include <__cmath/isinf.h> | ||||
#include <__cmath/isnan.h> | |||||
#include <__cmath/isnormal.h> | |||||
#include <__cmath/signbit.h> | |||||
#endif // signbit | #include <__type_traits/promote.h> | ||||
#include <limits> | |||||
#include <stdlib.h> | |||||
#include <type_traits> | |||||
// fpclassify | // fpclassify | ||||
#ifdef fpclassify | #ifdef fpclassify | ||||
template <class _A1> | template <class _A1> | ||||
_LIBCPP_INLINE_VISIBILITY | _LIBCPP_INLINE_VISIBILITY | ||||
int | int | ||||
Show All 36 Lines | |||||
template <class _A1> | template <class _A1> | ||||
inline _LIBCPP_INLINE_VISIBILITY | inline _LIBCPP_INLINE_VISIBILITY | ||||
typename std::enable_if<std::is_integral<_A1>::value, int>::type | typename std::enable_if<std::is_integral<_A1>::value, int>::type | ||||
fpclassify(_A1 __lcpp_x) _NOEXCEPT | fpclassify(_A1 __lcpp_x) _NOEXCEPT | ||||
{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; } | { return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; } | ||||
#endif // fpclassify | #endif // fpclassify | ||||
// isfinite | |||||
#ifdef isfinite | |||||
template <class _A1> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
#if __has_builtin(__builtin_isfinite) | |||||
return __builtin_isfinite(__lcpp_x); | |||||
#else | |||||
return isfinite(__lcpp_x); | |||||
#endif | |||||
} | |||||
#undef isfinite | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if< | |||||
std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, | |||||
bool>::type | |||||
isfinite(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x); | |||||
} | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if< | |||||
std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, | |||||
bool>::type | |||||
isfinite(_A1) _NOEXCEPT | |||||
{ return true; } | |||||
#endif // isfinite | |||||
// isinf | |||||
#ifdef isinf | |||||
template <class _A1> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
#if __has_builtin(__builtin_isinf) | |||||
return __builtin_isinf(__lcpp_x); | |||||
#else | |||||
return isinf(__lcpp_x); | |||||
#endif | |||||
} | |||||
#undef isinf | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if< | |||||
std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, | |||||
bool>::type | |||||
isinf(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x); | |||||
} | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if< | |||||
std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, | |||||
bool>::type | |||||
isinf(_A1) _NOEXCEPT | |||||
{ return false; } | |||||
#ifdef _LIBCPP_PREFERRED_OVERLOAD | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
isinf(float __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); } | |||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD | |||||
bool | |||||
isinf(double __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); } | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
isinf(long double __lcpp_x) _NOEXCEPT { return __libcpp_isinf(__lcpp_x); } | |||||
#endif | |||||
#endif // isinf | |||||
// isnan | |||||
#ifdef isnan | |||||
template <class _A1> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
#if __has_builtin(__builtin_isnan) | |||||
return __builtin_isnan(__lcpp_x); | |||||
#else | |||||
return isnan(__lcpp_x); | |||||
#endif | |||||
} | |||||
#undef isnan | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type | |||||
isnan(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x); | |||||
} | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if<std::is_integral<_A1>::value, bool>::type | |||||
isnan(_A1) _NOEXCEPT | |||||
{ return false; } | |||||
#ifdef _LIBCPP_PREFERRED_OVERLOAD | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
isnan(float __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); } | |||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD | |||||
bool | |||||
isnan(double __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); } | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
isnan(long double __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); } | |||||
#endif | |||||
#endif // isnan | |||||
// isnormal | |||||
#ifdef isnormal | |||||
template <class _A1> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
#if __has_builtin(__builtin_isnormal) | |||||
return __builtin_isnormal(__lcpp_x); | |||||
#else | |||||
return isnormal(__lcpp_x); | |||||
#endif | |||||
} | |||||
#undef isnormal | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type | |||||
isnormal(_A1 __lcpp_x) _NOEXCEPT | |||||
{ | |||||
return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x); | |||||
} | |||||
template <class _A1> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if<std::is_integral<_A1>::value, bool>::type | |||||
isnormal(_A1 __lcpp_x) _NOEXCEPT | |||||
{ return __lcpp_x != 0; } | |||||
#endif // isnormal | |||||
// isgreater | |||||
#ifdef isgreater | |||||
template <class _A1, class _A2> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
return isgreater(__lcpp_x, __lcpp_y); | |||||
} | |||||
#undef isgreater | |||||
template <class _A1, class _A2> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if | |||||
< | |||||
std::is_arithmetic<_A1>::value && | |||||
std::is_arithmetic<_A2>::value, | |||||
bool | |||||
>::type | |||||
isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
typedef typename std::__promote<_A1, _A2>::type type; | |||||
return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y); | |||||
} | |||||
#endif // isgreater | |||||
// isgreaterequal | |||||
#ifdef isgreaterequal | |||||
template <class _A1, class _A2> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
return isgreaterequal(__lcpp_x, __lcpp_y); | |||||
} | |||||
#undef isgreaterequal | |||||
template <class _A1, class _A2> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if | |||||
< | |||||
std::is_arithmetic<_A1>::value && | |||||
std::is_arithmetic<_A2>::value, | |||||
bool | |||||
>::type | |||||
isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
typedef typename std::__promote<_A1, _A2>::type type; | |||||
return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y); | |||||
} | |||||
#endif // isgreaterequal | |||||
// isless | |||||
#ifdef isless | |||||
template <class _A1, class _A2> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
return isless(__lcpp_x, __lcpp_y); | |||||
} | |||||
#undef isless | |||||
template <class _A1, class _A2> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if | |||||
< | |||||
std::is_arithmetic<_A1>::value && | |||||
std::is_arithmetic<_A2>::value, | |||||
bool | |||||
>::type | |||||
isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
typedef typename std::__promote<_A1, _A2>::type type; | |||||
return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y); | |||||
} | |||||
#endif // isless | |||||
// islessequal | |||||
#ifdef islessequal | |||||
template <class _A1, class _A2> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
return islessequal(__lcpp_x, __lcpp_y); | |||||
} | |||||
#undef islessequal | |||||
template <class _A1, class _A2> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if | |||||
< | |||||
std::is_arithmetic<_A1>::value && | |||||
std::is_arithmetic<_A2>::value, | |||||
bool | |||||
>::type | |||||
islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
typedef typename std::__promote<_A1, _A2>::type type; | |||||
return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y); | |||||
} | |||||
#endif // islessequal | |||||
// islessgreater | |||||
#ifdef islessgreater | |||||
template <class _A1, class _A2> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
return islessgreater(__lcpp_x, __lcpp_y); | |||||
} | |||||
#undef islessgreater | |||||
template <class _A1, class _A2> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if | |||||
< | |||||
std::is_arithmetic<_A1>::value && | |||||
std::is_arithmetic<_A2>::value, | |||||
bool | |||||
>::type | |||||
islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
typedef typename std::__promote<_A1, _A2>::type type; | |||||
return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y); | |||||
} | |||||
#endif // islessgreater | |||||
// isunordered | |||||
#ifdef isunordered | |||||
template <class _A1, class _A2> | |||||
_LIBCPP_INLINE_VISIBILITY | |||||
bool | |||||
__libcpp_isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
return isunordered(__lcpp_x, __lcpp_y); | |||||
} | |||||
#undef isunordered | |||||
template <class _A1, class _A2> | |||||
inline _LIBCPP_INLINE_VISIBILITY | |||||
typename std::enable_if | |||||
< | |||||
std::is_arithmetic<_A1>::value && | |||||
std::is_arithmetic<_A2>::value, | |||||
bool | |||||
>::type | |||||
isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT | |||||
{ | |||||
typedef typename std::__promote<_A1, _A2>::type type; | |||||
return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y); | |||||
} | |||||
#endif // isunordered | |||||
// abs | // abs | ||||
// | // | ||||
// handled in stdlib.h | // handled in stdlib.h | ||||
// div | // div | ||||
// | // | ||||
// handled in stdlib.h | // handled in stdlib.h | ||||
▲ Show 20 Lines • Show All 975 Lines • Show Last 20 Lines |