std::numeric_limits::infinity

static T infinity();
(C++11 前)
static constexpr T infinity();
(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

异常

(无) (C++11 前)
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


参阅

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

版本历史

  • (当前 | 先前 2017年7月17日 (一) 06:53Fruderica讨论 | 贡献. . (2,125字节) (-548). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:17P12bot讨论 | 贡献 . . (2,673字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:46P12bot讨论 | 贡献 . . (2,673字节) (-289). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 15:15P12bot讨论 | 贡献 . . (2,962字节) (+329). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 12:11P12讨论 | 贡献 . . (2,633字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (2,633字节) (-31). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:53P12讨论 | 贡献 . . (2,664字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (2,664字节) (+2,664). . (Translated from the English version using Google Translate)