extern "C++" {
#include <type_traits>
+#include <limits>
// signbit
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT
{
return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
}
+template <class _A1>
+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>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<
+ std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type
+signbit(_A1) _NOEXCEPT
+{ return false; }
+
#elif defined(_LIBCPP_MSVCRT)
template <typename _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT
{
return ::signbit(static_cast<typename std::__promote<_A1>::type>(__lcpp_x));
}
+template <class _A1>
+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>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<
+ std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type
+signbit(_A1) _NOEXCEPT
+{ return false; }
+
#endif // signbit
// fpclassify
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
+typename std::enable_if<std::is_floating_point<_A1>::value, int>::type
fpclassify(_A1 __lcpp_x) _NOEXCEPT
{
return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x);
}
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_integral<_A1>::value, int>::type
+fpclassify(_A1 __lcpp_x) _NOEXCEPT
+{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; }
+
#elif defined(_LIBCPP_MSVCRT)
template <typename _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
+typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
fpclassify(_A1 __lcpp_x) _NOEXCEPT
{
return ::fpclassify(static_cast<typename std::__promote<_A1>::type>(__lcpp_x));
}
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_integral<_A1>::value, int>::type
+fpclassify(_A1 __lcpp_x) _NOEXCEPT
+{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; }
+
#endif // fpclassify
// isfinite
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+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
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+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; }
+
#endif // isinf
// isnan
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+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; }
+
#endif // isnan
// isnormal
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+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
// <cmath>
#include <cmath>
+#include <limits>
#include <type_traits>
#include <cassert>
static_assert((std::is_same<decltype(std::signbit((long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(signbit(Ambiguous())), Ambiguous>::value), "");
assert(std::signbit(-1.0) == true);
+ assert(std::signbit(0u) == false);
+ assert(std::signbit(std::numeric_limits<unsigned>::max()) == false);
+ assert(std::signbit(0) == false);
+ assert(std::signbit(1) == false);
+ assert(std::signbit(-1) == true);
+ assert(std::signbit(std::numeric_limits<int>::max()) == false);
+ assert(std::signbit(std::numeric_limits<int>::min()) == true);
}
void test_fpclassify()
static_assert((std::is_same<decltype(std::fpclassify((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(fpclassify(Ambiguous())), Ambiguous>::value), "");
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<int>::max()) == FP_NORMAL);
+ assert(std::fpclassify(std::numeric_limits<int>::min()) == FP_NORMAL);
}
void test_isfinite()
static_assert((std::is_same<decltype(std::isfinite((long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isfinite(Ambiguous())), Ambiguous>::value), "");
assert(std::isfinite(-1.0) == true);
+ assert(std::isfinite(0) == true);
+ assert(std::isfinite(1) == true);
+ assert(std::isfinite(-1) == true);
+ assert(std::isfinite(std::numeric_limits<int>::max()) == true);
+ assert(std::isfinite(std::numeric_limits<int>::min()) == true);
}
void test_isnormal()
static_assert((std::is_same<decltype(std::isnormal((long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isnormal(Ambiguous())), Ambiguous>::value), "");
assert(std::isnormal(-1.0) == true);
+ assert(std::isnormal(0) == false);
+ assert(std::isnormal(1) == true);
+ assert(std::isnormal(-1) == true);
+ assert(std::isnormal(std::numeric_limits<int>::max()) == true);
+ assert(std::isnormal(std::numeric_limits<int>::min()) == true);
}
void test_isgreater()
static_assert((std::is_same<decltype(std::isinf(0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isinf((long double)0)), bool>::value), "");
assert(std::isinf(-1.0) == false);
+ assert(std::isinf(0) == false);
+ assert(std::isinf(1) == false);
+ assert(std::isinf(-1) == false);
+ assert(std::isinf(std::numeric_limits<int>::max()) == false);
+ assert(std::isinf(std::numeric_limits<int>::min()) == false);
}
void test_isless()
static_assert((std::is_same<decltype(std::isnan(0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isnan((long double)0)), bool>::value), "");
assert(std::isnan(-1.0) == false);
+ assert(std::isnan(0) == false);
+ assert(std::isnan(1) == false);
+ assert(std::isnan(-1) == false);
+ assert(std::isnan(std::numeric_limits<int>::max()) == false);
+ assert(std::isnan(std::numeric_limits<int>::min()) == false);
}
void test_isunordered()