std::numeric_limits<T>:: infinity
From cppreference.net
<
cpp
|
types
|
numeric limits
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Type support
| Basic types | |||||||||||||||||||||
| Fixed width integer types (C++11) | |||||||||||||||||||||
| Fixed width floating-point types (C++23) | |||||||||||||||||||||
|
|||||||||||||||||||||
| Numeric limits | |||||||||||||||||||||
| C numeric limits interface | |||||||||||||||||||||
| Runtime type information | |||||||||||||||||||||
|
|||||||||||||||||||||
std::numeric_limits
| Static constants | ||||
|
(C++11)
|
||||
| Static member functions | ||||
|
(C++11)
|
||||
|
numeric_limits::infinity
|
||||
| Helper types | ||||
|
static
T infinity
(
)
throw
(
)
;
|
(C++11 前) | |
|
static
constexpr
T infinity
(
)
noexcept
;
|
(C++11 起) | |
返回浮点类型
T
所表示的“正无穷大”特殊值。仅当
std::
numeric_limits
<
T
>
::
has_infinity
==
true
时该值才有意义。在 IEEE 754(最常用的浮点数二进制表示标准)中,正无穷大是指数位全为1、小数位全为0的数值。
返回值
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 |
示例
运行此代码
#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
参见
|
[static]
|
标识可以表示特殊值“正无穷大”的浮点类型
(公开静态成员常量) |