std::numeric_limits<T>:: infinity
From cppreference.net
<
cpp
|
types
|
numeric limits
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Type support
| Basic types | |||||||||||||||||||||
| Fixed width integer types (C++11) | |||||||||||||||||||||
| Fixed width floating-point types (C++23) | |||||||||||||||||||||
|
|||||||||||||||||||||
| Numeric limits | |||||||||||||||||||||
| C numeric limits interface | |||||||||||||||||||||
| Runtime type information | |||||||||||||||||||||
|
|||||||||||||||||||||
std::numeric_limits
| Static constants | ||||
|
(C++11)
|
||||
| Static member functions | ||||
|
(C++11)
|
||||
|
numeric_limits::infinity
|
||||
| Helper types | ||||
|
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
関連項目
|
[static]
|
特殊値「正の無限大」を表現できる浮動小数点型を識別する
(public static member constant) |