首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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)

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com