名稱空間
變體
操作

std::numeric_limits<T>::infinity

來自 cppreference.com
< cpp‎ | 型別‎ | 數值限制
 
 
 
 
 
static T infinity() throw();
(C++11 前)
static constexpr T infinity() noexcept;
(C++11 起)

返回浮點型別 T 所表示的特殊值“正無窮大”。僅當 std::numeric_limits<T>::has_infinity == true 時有意義。在 IEEE 754(浮點數最常見的二進位制表示)中,正無窮大是指數所有位都設定,分數所有位都清除的值。

[編輯] 返回值

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

[編輯] 參閱

確定可以表示特殊值“正無窮”的浮點型別
(public static member constant) [編輯]