std::numeric_limits::infinity

来自cppreference.com

 
 
 
类型支持
基本类型
基础类型
定宽整数类型 (C++11)
数值极限
C 数值极限接口
运行时类型信息
类型特性
类型类别
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
类型属性
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++17中过时)
(C++11)
类型特性常量
元函数
(C++17)
受支持操作
关系与属性查询
(C++11)
(C++11)
(C++11)
(C++11)
类型修改
(C++11)
(C++11)
(C++11)
类型变换
(C++11)
(C++11)
(C++17)
(C++11)(C++17中过时)
(C++17)
 
 
static T infinity()
(C++11 前)
static constexpr T infinity()
(C++11 起)
返回特殊值“正无穷大”为代表的浮点类型T。唯一有意义的,如果std::numeric_limits<T>::has_infinity == true。在IEEE 754中,最常见的浮点数字的二进制表示形式,是正无穷大的值的所有位的指数集和所有的馏分位清零.
原文:
Returns the special value "positive infinity", as represented by the floating-point type T. Only meaningful if std::numeric_limits<T>::has_infinity == true. In IEEE 754, the most common binary representation of floating-point numbers, the positive infinity is the value with all bits of the exponent set and all bits of the fraction cleared.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

目录

[编辑] 返回值

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

[编辑] 例外

noexcept规定:  
noexcept
  (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


[编辑] 另请参阅

鉴别能表示特殊值“正无穷大”的浮点类型
(公开静态成员常量) [编辑]