std::numeric_limits<T>::infinity
来自 cppreference.com
< cpp | types | numeric limits
static T infinity() throw(); |
(直到 C++11) | |
static constexpr T infinity() noexcept; |
(从 C++11 开始) | |
返回由浮点类型 T
表示的特殊值“正无穷大”。仅在 std::numeric_limits<T>::has_infinity == true 时才有意义。在 IEEE 754(最常见的浮点数二进制表示形式)中,正无穷大是指数的所有位都设置且分数的所有位都清除的值。
[edit] 返回值
T
|
std::numeric_limits<T>::infinity() |
/* 非特化 */ | T() |
bool | false |
char | 0 |
signed char | 0 |
unsigned char | 0 |
wchar_t | 0 |
char8_t (自 C++20 开始) | 0 |
char16_t (自 C++11 开始) | 0 |
char32_t (自 C++11 开始) | 0 |
short | 0 |
unsigned short | 0 |
int | 0 |
unsigned int | 0 |
long | 0 |
unsigned long | 0 |
long long (自 C++11 开始) | 0 |
unsigned long long (自 C++11 开始) | 0 |
float | HUGE_VALF |
double | HUGE_VAL |
long double | HUGE_VALL |
[edit] 示例
运行这段代码
#include <iostream> #include <limits> int main() { double max = std::numeric_limits<double>::max(); double inf = std::numeric_limits<double>::infinity(); if (inf > max) std::cout << inf << " is greater than " << max << '\n'; }
输出
inf is greater than 1.79769e+308
[edit] 另请参阅
[静态] |
识别可以表示特殊值“正无穷大”的浮点类型 (公共静态成员常量) |