std::numeric_limits<T>::has_infinity
来自cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
static const bool has_infinity; |
(C++11 前) | |
static constexpr bool has_infinity; |
(C++11 起) | |
std::numeric_limits<T>::has_infinity 的值对所有能够通过某个单独的特殊值表示正无穷大的类型 T 都是 true。此常量对所有浮点数类型都有意义,且保证在 std::numeric_limits<T>::is_iec559 == true 时始终是 true。
标准特化
T
|
std::numeric_limits<T>::has_infinity 的值
|
/* 未特化 */
|
false
|
bool
|
false
|
char
|
false
|
signed char
|
false
|
unsigned char
|
false
|
wchar_t
|
false
|
char8_t (C++20 起)
|
false
|
char16_t (C++11 起)
|
false
|
char32_t (C++11 起)
|
false
|
short
|
false
|
unsigned short
|
false
|
int
|
false
|
unsigned int
|
false
|
long
|
false
|
unsigned long
|
false
|
long long (C++11 起)
|
false
|
unsigned long long (C++11 起)
|
false
|
float
|
通常是 true
|
double
|
通常是 true
|
long double
|
通常是 true
|
示例
运行此代码
#include <iostream>
#include <limits>
int main()
{
std::cout << std::boolalpha
<< std::numeric_limits<int>::has_infinity << '\n'
<< std::numeric_limits<long>::has_infinity << '\n'
<< std::numeric_limits<float>::has_infinity << '\n'
<< std::numeric_limits<double>::has_infinity << '\n';
}
可能的输出:
false
false
true
true
参阅
[静态] |
返回给定类型的正无穷大值 (公开静态成员函数) |
[静态] |
鉴别能表示特殊值“安静的非数”(NaN)的浮点数类型 (公开静态成员常量) |
| 鉴别能表示特殊值“发信的非数”(NaN)的浮点数类型 (公开静态成员常量) |