MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
numeric_types.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_NUMERIC_NUMERIC_TYPES_HPP__
2#define MSTL_CORE_NUMERIC_NUMERIC_TYPES_HPP__
3
11
15
21
32template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
33MSTL_CONST_FUNCTION constexpr bool signbit(const T x) noexcept {
34 using UInt = make_integer_t<sizeof(T), false>;
35
36 const UInt bits = *reinterpret_cast<const UInt*>(&x);
37 constexpr UInt sign_mask = static_cast<UInt>(1) << (8 * sizeof(UInt) - 1);
38 return (bits & sign_mask) != 0;
39}
40
41
50template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
51MSTL_CONST_FUNCTION constexpr bool is_nan(const T x) noexcept {
52 return x != x;
53}
54
61template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
62MSTL_CONST_FUNCTION constexpr bool is_pos_infinity(const T x) noexcept {
63 return x == numeric_traits<T>::infinity();
64}
65
72template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
73MSTL_CONST_FUNCTION constexpr bool is_neg_infinity(const T x) noexcept {
74 return x == -numeric_traits<T>::infinity();
75}
76
84template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
85MSTL_CONST_FUNCTION constexpr bool is_infinity(const T x) noexcept {
87}
88
97template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
98MSTL_CONST_FUNCTION constexpr bool is_finite(const T x) noexcept {
99 return !_MSTL is_infinity(x) && !_MSTL is_nan(x);
100}
101
111template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
112MSTL_CONST_FUNCTION constexpr bool is_normal(const T x) noexcept {
113 if (!_MSTL is_finite(x)) return false;
114 if (x == 0) return false;
116}
117
127template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
128MSTL_CONST_FUNCTION constexpr bool is_subnormal(const T x) noexcept {
129 if (!_MSTL is_finite(x)) return false;
130 if (x == 0) return false;
132}
133
144template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
145MSTL_CONST_FUNCTION constexpr bool is_positive(const T x) noexcept {
146 return x > 0 || (x == 0 && !_MSTL signbit(x));
147}
148
159template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
160MSTL_CONST_FUNCTION constexpr bool is_negative(const T x) noexcept {
161 return x < 0 || (x == 0 && _MSTL signbit(x));
162}
163 // NumericTypeChecks
165
167#endif // MSTL_CORE_NUMERIC_NUMERIC_TYPES_HPP__
static MSTL_NODISCARD constexpr T infinity() noexcept
获取正无穷大表示
static MSTL_NODISCARD constexpr T min() noexcept
获取类型的最小值
MSTL_CONST_FUNCTION constexpr enable_if_t< is_signed_v< T >, T > absolute(const T x) noexcept
取绝对值(有符号数版本)
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_CONST_FUNCTION constexpr bool is_normal(const T x) noexcept
检查浮点数是否为正规数
MSTL_CONST_FUNCTION constexpr bool is_nan(const T x) noexcept
检查浮点数是否为NaN
MSTL_CONST_FUNCTION constexpr bool is_subnormal(const T x) noexcept
检查浮点数是否为次正规数
MSTL_CONST_FUNCTION constexpr bool is_finite(const T x) noexcept
检查浮点数是否为有限值
MSTL_CONST_FUNCTION constexpr bool signbit(const T x) noexcept
获取浮点数的符号位
MSTL_CONST_FUNCTION constexpr bool is_infinity(const T x) noexcept
检查浮点数是否为无穷大
MSTL_CONST_FUNCTION constexpr bool is_neg_infinity(const T x) noexcept
检查浮点数是否为负无穷大
MSTL_CONST_FUNCTION constexpr bool is_pos_infinity(const T x) noexcept
检查浮点数是否为正无穷大
MSTL_CONST_FUNCTION constexpr bool is_positive(const T x) noexcept
检查浮点数是否为正数
MSTL_CONST_FUNCTION constexpr bool is_negative(const T x) noexcept
检查浮点数是否为负数
typename make_integer< Size, IsSigned >::type make_integer_t
make_integer的便捷别名
MSTL数学函数库
MSTL数值特征