Namespaces
Variants
Actions

std::numeric_limits<T>::infinity

From cppreference.com
 
 
 
 
 
static T infinity()throw();
(until C++11)
staticconstexpr T infinity()noexcept;
(since C++11)

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.

[edit]Return value

Tstd::numeric_limits<T>::infinity()
/* non-specialized */T()
boolfalse
char0
signedchar0
unsignedchar0
wchar_t0
char8_t(since C++20)0
char16_t(since C++11)0
char32_t(since C++11)0
short0
unsignedshort0
int0
unsignedint0
long0
unsignedlong0
longlong(since C++11)0
unsignedlonglong(since C++11)0
floatHUGE_VALF
doubleHUGE_VAL
longdoubleHUGE_VALL

[edit]Example

#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';}

Output:

inf is greater than 1.79769e+308

[edit]See also

[static]
identifies floating-point types that can represent the special value "positive infinity"
(public static member constant)[edit]
close