std::numeric_limits::infinity
static T infinity(); | ? | (until C++11) |
---|---|---|
static constexpr T infinity(); | ? | (since C++11) |
返回特殊值“正无穷大”,如浮点类型所表示。T
.只有在以下情况下才有意义std::numeric_limits<T>::has_infinity==true
在ieee 754中,浮点数的最常见的二进制表示形式,正无穷大是指数集的所有位数和所有位数的清除值。
返回值
T | std::numeric_limits<T>::infinity() |
---|---|
/* non-specialized */ | T(); |
bool | false |
char | ?0? |
signed char | ?0? |
unsigned char | ?0? |
wchar_t | ?0? |
char16_t | ?0? |
char32_t | ?0? |
short | ?0? |
unsigned short | ?0? |
int | ?0? |
unsigned int | ?0? |
long | ?0? |
unsigned long | ?0? |
long long | ?0? |
unsigned long long | ?0? |
float | HUGE_VALF |
double | HUGE_VAL |
long double | HUGE_VALL |
例外
(none) | (until C++11) |
---|---|
noexcept specification: noexcept | (since C++11) |
例
二次
#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
二次
另见
has_infinity static | identifies floating-point types that can represent the special value "positive infinity" (public static member constant) |
---|
? cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com