numeric_limits クラス

このクラス テンプレートでは、組み込みの数値型の算術プロパティについて記述します。

構文

template <class Type>
    class numeric_limits

パラメーター

Type
プロパティがテスト、照会、設定対象になる基本的な要素のデータ型。 Type は宣言された constvolatileconst volatile である場合もあります。

解説

ヘッダーは次の型の明示的な特殊化を定義します。wchar_tboolcharsigned charunsigned charshortunsigned shortintunsigned intlongunsigned longfloatdoublelong doublelong longunsigned long longchar16_tchar32_t。 これらの明示的な特殊化では、メンバー numeric_limits::is_specializedtrueで、関連するすべてのメンバーには有効な値が含まれます。 プログラムによって、その他の明示的な特殊化を行えます。 クラスのほとんどのメンバー関数は、 floatの可能な実装について記述またはテストします。

任意の特殊化の場合、メンバーに有効な値が含まれません。 有効な値が含まれないメンバー オブジェクトは、0 (または false) を格納します。有効な値を返さないメンバー関数は Type(0)を返します。

静的な関数と定数

名前 説明
denorm_min 0 以外の最小の非正規化値を返します。
数字 型が精度を失うことなく表現できる基数桁数を返します。
digits10 型が精度を失うことなく表現できる小数点数桁数を返します。
epsilon 1 と、データ型が表すことのできる 1 より大きい最小値との差を返します。
has_denorm 型が非正規化値を許可するかどうかをテストします。
has_denorm_loss 精度の損失が、不正確な結果ではなく、非正規化の損失として検出されるかどうかをテストします。
has_infinity 型が正の無限大を表すことができるかどうかをテストします。
has_quiet_NaN 型が静かな (シグナルを発生させない) 非数 (NaN) を表せるかどうかをテストします。
has_signaling_NaN 型がシグナルを発生する非数 (NAN) を表せるかどうかをテストします。
infinity 型の正の無限大の表現 (使用可能な場合)。
is_bounded 型が表すことができる値のセットが有限かどうかをテストします。
is_exact 型で実行される計算に丸め誤差がないかどうかをテストします。
is_iec559 型が IEC 559 標準に準拠しているかどうかをテストします。
is_integer 型が整数を表せるかどうかをテストします。
is_modulo 型が剰余を表せるかどうかをテストします。
is_signed 型が符号付きを表せるかどうかをテストします。
is_specialized 型に、クラス テンプレート numeric_limitsで定義されている明示的な特殊化が含まれるかどうかをテストします。
lowest 負の最小有限値を返します。
max 型の最大の有限値を返します。
max_digits10 その型の 2 つの値が別個の異なる 10 進表現であることを確証するために必要な 10 進桁数を返します。
max_exponent 基数を累乗した場合に、浮動小数点型が有限値として表すことができる正の整数の最大指数を返します。
max_exponent10 10 の基数を累乗した場合に、浮動小数点型が有限値として表すことができる正の整数の最大指数を返します。
min 型の最小の正規化値を返します。
min_exponent 基数の底を累乗した場合に、浮動小数点型が有限値として表すことができる負の整数の最大指数を返します。
min_exponent10 10 の基数を累乗した場合に、浮動小数点型が有限値として表すことができる負の整数の最大指数を返します。
quiet_NaN 型の静かな非数表現 (NAN) を返します。
radix 型の表現に使用される、基数と呼ばれる整数の底を返します。
round_error 型の丸め誤差の最大値を返します。
round_style 実装において、浮動小数点値を整数値に丸め処理を行うために選択可能なさまざまな方式を記述した値を返します。
signaling_NaN 型のシグナリング非数 (NAN) の表現を返します。
tinyness_before 型が、値を丸める前に正規化された値として表現するには小さすぎることを確認できるかどうかをテストします。
traps 型において算術例外に関するレポートをトラップするように実装されているかどうかをテストします。

denorm_min

0 以外の最小の非正規化値を返します。

static constexpr Type denorm_min() throw();

戻り値

0 以外の最小の非正規化値。

解説

long double は、C++ コンパイラにとっては double と同じです。

関数は、型の最小値を返します。これは、has_denormdenorm_present と等しくない場合は min と同じになります。

// numeric_limits_denorm_min.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The smallest nonzero denormalized value" << endl
        << "for float objects is: "
        << numeric_limits<float>::denorm_min( ) << endl;
   cout << "The smallest nonzero denormalized value" << endl
        << "for double objects is: "
        << numeric_limits<double>::denorm_min( ) << endl;
   cout << "The smallest nonzero denormalized value" << endl
        << "for long double objects is: "
        << numeric_limits<long double>::denorm_min( ) << endl;

   // A smaller value will round to zero
   cout << numeric_limits<float>::denorm_min( )/2 <<endl;
   cout << numeric_limits<double>::denorm_min( )/2 <<endl;
   cout << numeric_limits<long double>::denorm_min( )/2 <<endl;
}
The smallest nonzero denormalized value
for float objects is: 1.4013e-045
The smallest nonzero denormalized value
for double objects is: 4.94066e-324
The smallest nonzero denormalized value
for long double objects is: 4.94066e-324
0
0
0

数値

型が精度を失うことなく表現できる基数桁数を返します。

static constexpr int digits = 0;

戻り値

型が精度を失うことなく表現できる基数桁数。

解説

メンバーは、型が変更なしで表すことができる基数桁数を格納します。これは、定義済みの整数型の任意の符号ビット以外のビット数、または定義済みの浮動小数点型の仮数部桁数になります。

// numeric_limits_digits_min.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << numeric_limits<float>::digits <<endl;
   cout << numeric_limits<double>::digits <<endl;
   cout << numeric_limits<long double>::digits <<endl;
   cout << numeric_limits<int>::digits <<endl;
   cout << numeric_limits<__int64>::digits <<endl;
}
24
53
53
31
63

digits10

型が精度を失うことなく表現できる小数点数桁数を返します。

static constexpr int digits10 = 0;

戻り値

型が精度を失うことなく表現できる小数点数桁数。

// numeric_limits_digits10.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << numeric_limits<float>::digits10 <<endl;
   cout << numeric_limits<double>::digits10 <<endl;
   cout << numeric_limits<long double>::digits10 <<endl;
   cout << numeric_limits<int>::digits10 <<endl;
   cout << numeric_limits<__int64>::digits10 <<endl;
   float f = (float)99999999;
   cout.precision ( 10 );
   cout << "The float is; " << f << endl;
}
6
15
15
9
18
The float is; 100000000

epsilon

関数は、1 と、データ型が表現可能な 1 より大きい最小値との間の差を返します。

static constexpr Type epsilon() throw();

戻り値

1 と、データ型が表現可能な 1 より大きい最小値との間の差。

解説

値は、float 型の場合は FLT_EPSILON です。 型の epsilon は、N + epsilon + N が表現可能になるように、正の浮動小数点数 N の最小値になります。

// numeric_limits_epsilon.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The difference between 1 and the smallest "
        << "value greater than 1" << endl
        << "for float objects is: "
        << numeric_limits<float>::epsilon( ) << endl;
   cout << "The difference between 1 and the smallest "
        << "value greater than 1" << endl
        << "for double objects is: "
        << numeric_limits<double>::epsilon( ) << endl;
   cout << "The difference between 1 and the smallest "
        << "value greater than 1" << endl
        << "for long double objects is: "
        << numeric_limits<long double>::epsilon( ) << endl;
}
The difference between 1 and the smallest value greater than 1
for float objects is: 1.19209e-007
The difference between 1 and the smallest value greater than 1
for double objects is: 2.22045e-016
The difference between 1 and the smallest value greater than 1
for long double objects is: 2.22045e-016

has_denorm

型が非正規化値を許可するかどうかをテストします。

static constexpr float_denorm_style has_denorm = denorm_absent;

戻り値

const float_denorm_style 型の列挙値で、型が非正規化値を許可するかどうかを示します。

解説

メンバーは、非正規化値を持つ浮動小数点型の場合は denorm_present (事実上、指数ビットの可変数) を格納します。

// numeric_limits_has_denorm.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects allow denormalized values: "
        << numeric_limits<float>::has_denorm
        << endl;
   cout << "Whether double objects allow denormalized values: "
        << numeric_limits<double>::has_denorm
        << endl;
   cout << "Whether long int objects allow denormalized values: "
        << numeric_limits<long int>::has_denorm
        << endl;
}
Whether float objects allow denormalized values: 1
Whether double objects allow denormalized values: 1
Whether long int objects allow denormalized values: 0

has_denorm_loss

精度の損失が、不正確な結果ではなく、非正規化の損失として検出されるかどうかをテストします。

static constexpr bool has_denorm_loss = false;

戻り値

精度の損失が非正規化の損失として検出される場合は true、そうでない場合は false

解説

メンバーは、非正規化された結果となるか (正規化値として表現するには小さすぎる)、あるいは不正確である (指数の範囲と精度の制約を受けない結果とは異なる) ため、値の精度が損失されたかどうかを判別する型の場合は true を格納します。これは、一部の結果に影響を与える可能性がある、IEC 559 浮動小数点表現でのオプションです。

// numeric_limits_has_denorm_loss.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects can detect denormalized loss: "
        << numeric_limits<float>::has_denorm_loss
        << endl;
   cout << "Whether double objects can detect denormalized loss: "
        << numeric_limits<double>::has_denorm_loss
        << endl;
   cout << "Whether long int objects can detect denormalized loss: "
        << numeric_limits<long int>::has_denorm_loss
        << endl;
}
Whether float objects can detect denormalized loss: 1
Whether double objects can detect denormalized loss: 1
Whether long int objects can detect denormalized loss: 0

has_infinity

型が正の無限大を表すことができるかどうかをテストします。

static constexpr bool has_infinity = false;

戻り値

型が正の無限大を表すことができる場合は true、それ以外の場合は false

解説

メンバーは、is_iec559true の場合、true を返します。

// numeric_limits_has_infinity.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have infinity: "
        << numeric_limits<float>::has_infinity
        << endl;
   cout << "Whether double objects have infinity: "
        << numeric_limits<double>::has_infinity
        << endl;
   cout << "Whether long int objects have infinity: "
        << numeric_limits<long int>::has_infinity
        << endl;
}
Whether float objects have infinity: 1
Whether double objects have infinity: 1
Whether long int objects have infinity: 0

has_quiet_NaN

型が静かな (シグナルを発生させない) 非数 (NaN) を表せるかどうかをテストします。

static constexpr bool has_quiet_NaN = false;

戻り値

type に静かな NaN の表現がある場合は true、そうでない場合は false

解説

静かな NaN は、式でのその存在についてのシグナルを発生させない非数のエンコードです。 is_iec559 が true の場合、戻り値は true です。

// numeric_limits_has_quiet_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have quiet_NaN: "
        << numeric_limits<float>::has_quiet_NaN
        << endl;
   cout << "Whether double objects have quiet_NaN: "
        << numeric_limits<double>::has_quiet_NaN
        << endl;
   cout << "Whether long int objects have quiet_NaN: "
        << numeric_limits<long int>::has_quiet_NaN
        << endl;
}
Whether float objects have quiet_NaN: 1
Whether double objects have quiet_NaN: 1
Whether long int objects have quiet_NaN: 0

has_signaling_NaN

型がシグナルを発生する非数 (NAN) を表せるかどうかをテストします。

static constexpr bool has_signaling_NaN = false;

戻り値

型がシグナルを発生する NAN を表せる場合は true、それ以外の場合は false

解説

シグナルを発生する NaN は、式でのその存在についてのシグナルを発生させる非数のエンコードです。 is_iec559 が true の場合、戻り値は true です。

// numeric_limits_has_signaling_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have a signaling_NaN: "
        << numeric_limits<float>::has_signaling_NaN
        << endl;
   cout << "Whether double objects have a signaling_NaN: "
        << numeric_limits<double>::has_signaling_NaN
        << endl;
   cout << "Whether long int objects have a signaling_NaN: "
        << numeric_limits<long int>::has_signaling_NaN
        << endl;
}
Whether float objects have a signaling_NaN: 1
Whether double objects have a signaling_NaN: 1
Whether long int objects have a signaling_NaN: 0

infinity

型の正の無限大の表現 (使用可能な場合)。

static constexpr Type infinity() throw();

戻り値

型の正の無限大の表現 (使用可能な場合)。

解説

has_infinitytrue である場合にのみ、戻り値に意味があります。

// numeric_limits_infinity.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << numeric_limits<float>::has_infinity <<endl;
   cout << numeric_limits<double>::has_infinity<<endl;
   cout << numeric_limits<long double>::has_infinity <<endl;
   cout << numeric_limits<int>::has_infinity <<endl;
   cout << numeric_limits<__int64>::has_infinity <<endl;

   cout << "The representation of infinity for type float is: "
        << numeric_limits<float>::infinity( ) <<endl;
   cout << "The representation of infinity for type double is: "
        << numeric_limits<double>::infinity( ) <<endl;
   cout << "The representation of infinity for type long double is: "
        << numeric_limits<long double>::infinity( ) <<endl;
}
1
1
1
0
0
The representation of infinity for type float is: inf
The representation of infinity for type double is: inf
The representation of infinity for type long double is: inf

is_bounded

型が表すことができる値のセットが有限かどうかをテストします。

static constexpr bool is_bounded = false;

戻り値

型が表すことができる値のセットが範囲指定されている場合は true、それ以外の場合は false

解説

定義済みのすべての型が表すことができる値のセットは範囲指定されており、true を返します。

// numeric_limits_is_bounded.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have bounded set "
        << "of representable values: "
        << numeric_limits<float>::is_bounded
        << endl;
   cout << "Whether double objects have bounded set "
        << "of representable values: "
        << numeric_limits<double>::is_bounded
        << endl;
   cout << "Whether long int objects have bounded set "
        << "of representable values: "
        << numeric_limits<long int>::is_bounded
        << endl;
   cout << "Whether unsigned char objects have bounded set "
        << "of representable values: "
        << numeric_limits<unsigned char>::is_bounded
        << endl;
}
Whether float objects have bounded set of representable values: 1
Whether double objects have bounded set of representable values: 1
Whether long int objects have bounded set of representable values: 1
Whether unsigned char objects have bounded set of representable values: 1

is_exact

型で実行される計算に丸め誤差がないかどうかをテストします。

static constexpr bool is_exact = false;

戻り値

計算に丸め誤差がない場合は true、それ以外の場合は false

解説

定義済みのすべての整数型には値の正確な表現があり、false を返します。 固定小数点表現または有理表現も正確であると見なされますが、浮動小数点表現は正確ではありません。

// numeric_limits_is_exact.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have calculations "
        << "free of rounding errors: "
        << numeric_limits<float>::is_exact
        << endl;
   cout << "Whether double objects have calculations "
        << "free of rounding errors: "
        << numeric_limits<double>::is_exact
        << endl;
   cout << "Whether long int objects have calculations "
        << "free of rounding errors: "
        << numeric_limits<long int>::is_exact
        << endl;
   cout << "Whether unsigned char objects have calculations "
        << "free of rounding errors: "
        << numeric_limits<unsigned char>::is_exact
        << endl;
}
Whether float objects have calculations free of rounding errors: 0
Whether double objects have calculations free of rounding errors: 0
Whether long int objects have calculations free of rounding errors: 1
Whether unsigned char objects have calculations free of rounding errors: 1

is_iec559

型が IEC 559 標準に準拠しているかどうかをテストします。

static constexpr bool is_iec559 = false;

戻り値

型が IEC 559 標準に準拠している場合は true、それ以外の場合は false

解説

IEC 559 は、浮動小数点値に関する国際標準であり、米国では IEEE 754 とも呼ばれます。

// numeric_limits_is_iec559.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects conform to iec559 standards: "
        << numeric_limits<float>::is_iec559
        << endl;
   cout << "Whether double objects conform to iec559 standards: "
        << numeric_limits<double>::is_iec559
        << endl;
   cout << "Whether int objects conform to iec559 standards: "
        << numeric_limits<int>::is_iec559
        << endl;
   cout << "Whether unsigned char objects conform to iec559 standards: "
        << numeric_limits<unsigned char>::is_iec559
        << endl;
}
Whether float objects conform to iec559 standards: 1
Whether double objects conform to iec559 standards: 1
Whether int objects conform to iec559 standards: 0
Whether unsigned char objects conform to iec559 standards: 0

is_integer

型が整数を表せるかどうかをテストします。

static constexpr bool is_integer = false;

戻り値

型が整数を表せる場合は true、それ以外の場合は false

解説

定義済みのすべて整数型は、整数を表せます。

// numeric_limits_is_integer.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have an integral representation: "
        << numeric_limits<float>::is_integer
        << endl;
   cout << "Whether double objects have an integral representation: "
        << numeric_limits<double>::is_integer
        << endl;
   cout << "Whether int objects have an integral representation: "
        << numeric_limits<int>::is_integer
        << endl;
   cout << "Whether unsigned char objects have an integral representation: "
        << numeric_limits<unsigned char>::is_integer
        << endl;
}
Whether float objects have an integral representation: 0
Whether double objects have an integral representation: 0
Whether int objects have an integral representation: 1
Whether unsigned char objects have an integral representation: 1

is_modulo

type が剰余を表せるかどうかをテストします。

static constexpr bool is_modulo = false;

戻り値

型が剰余を表せる場合は true、それ以外の場合は false

解説

剰余表現は、すべての結果がいくつかの値を法とする剰余を結果とする表現です。 定義済みのすべての符号なし整数型は剰余を表せます。

// numeric_limits_is_modulo.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have a modulo representation: "
        << numeric_limits<float>::is_modulo
        << endl;
   cout << "Whether double objects have a modulo representation: "
        << numeric_limits<double>::is_modulo
        << endl;
   cout << "Whether signed char objects have a modulo representation: "
        << numeric_limits<signed char>::is_modulo
        << endl;
   cout << "Whether unsigned char objects have a modulo representation: "
        << numeric_limits<unsigned char>::is_modulo
        << endl;
}
Whether float objects have a modulo representation: 0
Whether double objects have a modulo representation: 0
Whether signed char objects have a modulo representation: 1
Whether unsigned char objects have a modulo representation: 1

is_signed

型が符号付きを表せるかどうかをテストします。

static constexpr bool is_signed = false;

戻り値

型が符号付きを表せる場合は true、それ以外の場合は false

解説

メンバーは、符号付きを表せる型の場合は true を格納します。これは、定義済みのすべての浮動小数点型および符号付き整数型の場合に該当します。

// numeric_limits_is_signaled.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have a signed representation: "
        << numeric_limits<float>::is_signed
        << endl;
   cout << "Whether double objects have a signed representation: "
        << numeric_limits<double>::is_signed
        << endl;
   cout << "Whether signed char objects have a signed representation: "
        << numeric_limits<signed char>::is_signed
        << endl;
   cout << "Whether unsigned char objects have a signed representation: "
        << numeric_limits<unsigned char>::is_signed
        << endl;
}
Whether float objects have a signed representation: 1
Whether double objects have a signed representation: 1
Whether signed char objects have a signed representation: 1
Whether unsigned char objects have a signed representation: 0

is_specialized

型に、クラス テンプレート numeric_limitsで定義されている明示的な特殊化が含まれるかどうかをテストします。

static constexpr bool is_specialized = false;

戻り値

型に、クラス テンプレートで定義されている明示的な特殊化が含まれる場合は true、それ以外の場合は false

解説

ポインター以外のすべてのスカラー型には、クラス テンプレート numeric_limits に対して定義されている明示的な特殊化があります。

// numeric_limits_is_specialized.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float objects have an explicit "
        << "specialization in the class: "
        << numeric_limits<float>::is_specialized
        << endl;
   cout << "Whether float* objects have an explicit "
        << "specialization in the class: "
        << numeric_limits<float*>::is_specialized
        << endl;
   cout << "Whether int objects have an explicit "
        << "specialization in the class: "
        << numeric_limits<int>::is_specialized
        << endl;
   cout << "Whether int* objects have an explicit "
        << "specialization in the class: "
        << numeric_limits<int*>::is_specialized
        << endl;
}
Whether float objects have an explicit specialization in the class: 1
Whether float* objects have an explicit specialization in the class: 0
Whether int objects have an explicit specialization in the class: 1
Whether int* objects have an explicit specialization in the class: 0

最小

負の最小有限値を返します。

static constexpr Type lowest() throw();

戻り値

負の最小有限値を返します。

解説

型の負の最小有限値 (通常、整数型の場合は min() と浮動小数点型の場合は -max()) を返します。 is_boundedtrue である場合、戻り値に意味があります。

最大

型の最大の有限値を返します。

static constexpr Type max() throw();

戻り値

型の最大の有限値。

解説

最大の有限値は、int 型の場合は INT_MAX、型 float の場合は FLT_MAX です。 is_boundedtrue である場合、戻り値に意味があります。

// numeric_limits_max.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main() {
   cout << "The maximum value for type float is:  "
        << numeric_limits<float>::max( )
        << endl;
   cout << "The maximum value for type double is:  "
        << numeric_limits<double>::max( )
        << endl;
   cout << "The maximum value for type int is:  "
        << numeric_limits<int>::max( )
        << endl;
   cout << "The maximum value for type short int is:  "
        << numeric_limits<short int>::max( )
        << endl;
}

max_digits10

その型の別個の 2 つの値が別個の 10 進表現であることを確証するために必要な 10 進桁数を返します。

static constexpr int max_digits10 = 0;

戻り値

その型の別個の 2 つの値が別個の 10 進表現であることを確証するために必要な 10 進桁数を返します。

解説

このメンバーは、その型の別個の 2 つの値が別個の 10 進表現であることを確証するために必要な 10 進桁数を格納します。

max_exponent

基数を累乗した場合に、浮動小数点型が有限値として表すことができる正の整数の最大指数を返します。

static constexpr int max_exponent = 0;

戻り値

型が表すことができる、整数基数に基づく最大指数。

解説

メンバー関数の戻り値は、浮動小数点型に対してのみ意味があります。 max_exponent は、float 型の場合は値 FLT_MAX_EXP です。

// numeric_limits_max_exponent.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The maximum radix-based exponent for type float is:  "
        << numeric_limits<float>::max_exponent
        << endl;
   cout << "The maximum radix-based exponent for type double is:  "
        << numeric_limits<double>::max_exponent
        << endl;
   cout << "The maximum radix-based exponent for type long double is:  "
        << numeric_limits<long double>::max_exponent
        << endl;
}
The maximum radix-based exponent for type float is:  128
The maximum radix-based exponent for type double is:  1024
The maximum radix-based exponent for type long double is:  1024

max_exponent10

10 の基数を累乗した場合に、浮動小数点型が有限値として表すことができる正の整数の最大指数を返します。

static constexpr int max_exponent10 = 0;

戻り値

型が表すことができる、10 の基数に基づく整数の最大指数。

解説

メンバー関数の戻り値は、浮動小数点型に対してのみ意味があります。 max_exponent は、float 型の場合は値 FLT_MAX_10 です。

// numeric_limits_max_exponent10.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The maximum base 10 exponent for type float is:  "
           << numeric_limits<float>::max_exponent10
           << endl;
   cout << "The maximum base 10 exponent for type double is:  "
           << numeric_limits<double>::max_exponent10
           << endl;
   cout << "The maximum base 10 exponent for type long double is:  "
           << numeric_limits<long double>::max_exponent10
           << endl;
}
The maximum base 10 exponent for type float is:  38
The maximum base 10 exponent for type double is:  308
The maximum base 10 exponent for type long double is:  308

最小

型の最小の正規化値を返します。

static constexpr Type min() throw();

戻り値

型の最小の正規化値。

解説

最小の正規化値は、int 型の場合は INT_MIN、float 型の場合は FLT_MIN です。 is_boundedtrue であるか、is_signedfalse である場合、戻り値に意味があります。

// numeric_limits_min.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The minimum value for type float is:  "
        << numeric_limits<float>::min( )
        << endl;
   cout << "The minimum value for type double is:  "
        << numeric_limits<double>::min( )
        << endl;
   cout << "The minimum value for type int is:  "
        << numeric_limits<int>::min( )
        << endl;
   cout << "The minimum value for type short int is:  "
        << numeric_limits<short int>::min( )
        << endl;
}
The minimum value for type float is:  1.17549e-038
The minimum value for type double is:  2.22507e-308
The minimum value for type int is:  -2147483648
The minimum value for type short int is:  -32768

min_exponent

基数の底を累乗した場合に、浮動小数点型が有限値として表すことができる負の整数の最大指数を返します。

static constexpr int min_exponent = 0;

戻り値

型が表すことができる、整数基数に基づく最小指数。

解説

メンバー関数は、浮動小数点型に対してのみ意味があります。 min_exponent は、float 型の場合は値 FLT_MIN_EXP です。

// numeric_limits_min_exponent.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The minimum radix-based exponent for type float is:  "
        << numeric_limits<float>::min_exponent
        << endl;
   cout << "The minimum radix-based exponent for type double is:  "
        << numeric_limits<double>::min_exponent
        << endl;
   cout << "The minimum radix-based exponent for type long double is:  "
         << numeric_limits<long double>::min_exponent
        << endl;
}
The minimum radix-based exponent for type float is:  -125
The minimum radix-based exponent for type double is:  -1021
The minimum radix-based exponent for type long double is:  -1021

min_exponent10

10 の基数を累乗した場合に、浮動小数点型が有限値として表すことができる負の整数の最大指数を返します。

static constexpr int min_exponent10 = 0;

戻り値

型が表すことができる、10 の基数に基づく整数の最小指数。

解説

メンバー関数は、浮動小数点型に対してのみ意味があります。 min_exponent10 は、float 型の場合は値 FLT_MIN_10_EXP です。

// numeric_limits_min_exponent10.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The minimum base 10 exponent for type float is:  "
        << numeric_limits<float>::min_exponent10
        << endl;
   cout << "The minimum base 10 exponent for type double is:  "
        << numeric_limits<double>::min_exponent10
        << endl;
   cout << "The minimum base 10 exponent for type long double is:  "
        << numeric_limits<long double>::min_exponent10
        << endl;
}
The minimum base 10 exponent for type float is:  -37
The minimum base 10 exponent for type double is:  -307
The minimum base 10 exponent for type long double is:  -307

quiet_NaN

型の静かな非数表現 (NAN) を返します。

static constexpr Type quiet_NaN() throw();

戻り値

型の静かな NAN。

解説

has_quiet_NaNtrue である場合にのみ、戻り値に意味があります。

// numeric_limits_quiet_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The quiet NaN for type float is:  "
        << numeric_limits<float>::quiet_NaN( )
        << endl;
   cout << "The quiet NaN for type int is:  "
        << numeric_limits<int>::quiet_NaN( )
        << endl;
   cout << "The quiet NaN for type long double is:  "
        << numeric_limits<long double>::quiet_NaN( )
        << endl;
}
The quiet NaN for type float is:  1.#QNAN
The quiet NaN for type int is:  0
The quiet NaN for type long double is:  1.#QNAN

radix

型の表現に使用される、基数と呼ばれる整数の底を返します。

static constexpr int radix = 0;

戻り値

型の表現の整数の底。

解説

底は、定義済みの整数型の場合は 2 であり、指数を累乗する際に使用されます。または、定義済みの浮動小数点型の場合は FLT_RADIX です。

// numeric_limits_radix.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The base for type float is:  "
        << numeric_limits<float>::radix
        << endl;
   cout << "The base for type int is:  "
        << numeric_limits<int>::radix
        << endl;
   cout << "The base for type long double is:  "
        << numeric_limits<long double>::radix
        << endl;
}
The base for type float is:  2
The base for type int is:  2
The base for type long double is:  2

round_error

型の丸め誤差の最大値を返します。

static constexpr Type round_error() throw();

戻り値

型の丸め誤差の最大値。

// numeric_limits_round_error.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The maximum rounding error for type float is:  "
        << numeric_limits<float>::round_error( )
        << endl;
   cout << "The maximum rounding error for type int is:  "
        << numeric_limits<int>::round_error( )
        << endl;
   cout << "The maximum rounding error for type long double is:  "
        << numeric_limits<long double>::round_error( )
        << endl;
}
The maximum rounding error for type float is:  0.5
The maximum rounding error for type int is:  0
The maximum rounding error for type long double is:  0.5

round_style

実装において、浮動小数点値を整数値に丸め処理を行うために選択可能なさまざまな方式を記述した値を返します。

static constexpr float_round_style round_style = round_toward_zero;

戻り値

丸め処理スタイルを記述した、float_round_style 列挙型からの値。

解説

メンバーは、実装において、浮動小数点値を整数値に丸め処理を行うために選択可能なさまざまな方式を記述した値を格納します。

丸め処理スタイルはこの実装でハードコーディングされています。このため、プログラムが別の丸め処理モードを開始しても、値が変わることはありません。

// numeric_limits_round_style.cpp
// compile with: /EHsc
#include <iostream>
#include <float.h>
#include <limits>

using namespace std;

int main( )
{
   cout << "The rounding style for a double type is: "
        << numeric_limits<double>::round_style << endl;
   _controlfp_s(NULL,_RC_DOWN,_MCW_RC );
   cout << "The rounding style for a double type is now: "
        << numeric_limits<double>::round_style << endl;
   cout << "The rounding style for an int type is: "
        << numeric_limits<int>::round_style << endl;
}
The rounding style for a double type is: 1
The rounding style for a double type is now: 1
The rounding style for an int type is: 0

signaling_NaN

型のシグナリング非数 (NAN) の表現を返します。

static constexpr Type signaling_NaN() throw();

戻り値

型のシグナリング NAN の表現。

解説

has_signaling_NaNtrue である場合にのみ、戻り値に意味があります。

// numeric_limits_signaling_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The signaling NaN for type float is:  "
        << numeric_limits<float>::signaling_NaN( )
        << endl;
   cout << "The signaling NaN for type int is:  "
        << numeric_limits<int>::signaling_NaN( )
        << endl;
   cout << "The signaling NaN for type long double is:  "
        << numeric_limits<long double>::signaling_NaN( )
        << endl;
}

tinyness_before

型が、値を丸める前に正規化された値として表現するには小さすぎることを確認できるかどうかをテストします。

static constexpr bool tinyness_before = false;

戻り値

型が、丸め処理を行う前に小さい値を検出できる場合は true、検出できない場合は false

解説

小さい値を検出できる型は、IEC 559 の浮動小数点表現にオプションとして含まれており、これを実装するといくつかの結果に影響を与える可能性があります。

// numeric_limits_tinyness_before.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float types can detect tinyness before rounding: "
        << numeric_limits<float>::tinyness_before
        << endl;
   cout << "Whether double types can detect tinyness before rounding: "
        << numeric_limits<double>::tinyness_before
        << endl;
   cout << "Whether long int types can detect tinyness before rounding: "
        << numeric_limits<long int>::tinyness_before
        << endl;
   cout << "Whether unsigned char types can detect tinyness before rounding: "
        << numeric_limits<unsigned char>::tinyness_before
        << endl;
}
Whether float types can detect tinyness before rounding: 1
Whether double types can detect tinyness before rounding: 1
Whether long int types can detect tinyness before rounding: 0
Whether unsigned char types can detect tinyness before rounding: 0

traps

型において算術例外に関するレポートをトラップするように実装されているかどうかをテストします。

static constexpr bool traps = false;

戻り値

型においてトラップが実装されている場合は true、実装されていない場合は false

// numeric_limits_traps.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "Whether float types have implemented trapping: "
        << numeric_limits<float>::traps
        << endl;
   cout << "Whether double types have implemented trapping: "
        << numeric_limits<double>::traps
        << endl;
   cout << "Whether long int types have implemented trapping: "
        << numeric_limits<long int>::traps
        << endl;
   cout << "Whether unsigned char types have implemented trapping: "
        << numeric_limits<unsigned char>::traps
        << endl;
}
Whether float types have implemented trapping: 1
Whether double types have implemented trapping: 1
Whether long int types have implemented trapping: 0
Whether unsigned char types have implemented trapping: 0