numeric_limits (classe)

Il modello di classe descrive le proprietà aritmetiche dei tipi numerici predefiniti.

Sintassi

template <class Type>
    class numeric_limits

Parametri

Type
Il tipo di dati elemento fondamentale le cui proprietà vengono testate, sottoposte a query o impostate. Il tipo può anche essere dichiarato const, volatileo const volatile.

Osservazioni:

L'intestazione definisce specializzazioni esplicite per i tipi , , signed char, , intunsigned charunsigned long longlong longdoublefloatlong doubleunsigned intunsigned longchar16_tlongshortunsigned shorte .char32_tcharboolwchar_t Per queste specializzazioni esplicite, il membro numeric_limits::is_specialized è truee tutti i membri rilevanti hanno valori significativi. Il programma può fornire ulteriori specializzazioni esplicite. La maggior parte delle funzioni membro della classe descrive o testa le implementazioni possibili di float.

Per una specializzazione arbitraria, nessun membro dispone di valori significativi. Un oggetto membro che non dispone di un valore significativo archivia zero (o false) e restituisce una funzione membro che non restituisce un valore significativo Type(0).

Funzioni e costanti statiche

Nome Descrizione
denorm_min Restituisce il più piccolo valore denormalizzato diverso da zero.
cifre Restituisce il numero di cifre radice che il tipo può rappresentare senza perdita di precisione.
digits10 Restituisce il numero di cifre decimali che il tipo può rappresentare senza perdita di precisione.
epsilon Restituisce la differenza tra 1 e il valore più piccolo maggiore di 1 che il tipo di dati può rappresentare.
has_denorm Verifica se un tipo consente valori denormalizzati.
has_denorm_loss Verifica se la perdita di precisione viene rilevata come una perdita di denormalizzazione anziché come un risultato inesatto.
has_infinity Verifica se un tipo dispone di una rappresentazione per un numero infinito positivo.
has_quiet_NaN Verifica se un tipo ha una rappresentazione per un numero non silenzioso (NAN), che non segnala.
has_signaling_NaN Verifica se un tipo dispone di una rappresentazione per un valore diverso da un numero (NaN) con segnalazione.
infinity La rappresentazione di un numero infinito positivo, se disponibile.
is_bounded Verifica se il set di valori che può rappresentare è finito.
is_exact Verifica se i calcoli eseguiti su un tipo sono privi di errori di arrotondamento.
is_iec559 Verifica se un tipo è conforme agli standard IEC 559.
is_integer Verifica se un tipo ha una rappresentazione in forma di Integer.
is_modulo Verifica se un tipo ha una rappresentazione in forma di modulo.
is_signed Verifica se un tipo ha una rappresentazione firmata.
is_specialized Verifica se un tipo ha una specializzazione esplicita definita nel modello numeric_limitsdi classe .
lowest Restituisce il valore finito più negativo.
max Restituisce il valore massimo finito per un tipo.
max_digits10 Restituisce il numero di cifre decimali richiesto per garantire che due valori distinti del tipo abbiano rappresentazioni decimali distinte.
max_exponent Restituisce l'esponente integrale positivo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di radice è elevata a tale potenza.
max_exponent10 Restituisce l'esponente integrale positivo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di dieci è elevata a tale potenza.
min Restituisce il valore normalizzato minimo per un tipo.
min_exponent Restituisce l'esponente integrale negativo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di radice è elevata a tale potenza.
min_exponent10 Restituisce l'esponente integrale negativo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di dieci è elevata a tale potenza.
quiet_NaN Restituisce la rappresentazione di un valore diverso da un numero (NaN) non interattivo per il tipo.
radix Restituisce la base integrale, detta radice, usata per la rappresentazione di un tipo.
round_error Restituisce il valore massimo per il tipo di errore di arrotondamento.
round_style Restituisce un valore che descrive i vari metodi che un'implementazione può scegliere per l'arrotondamento di un valore a virgola mobile in un valore intero.
signaling_NaN Restituisce la rappresentazione di un valore diverso da un numero (NaN) con segnalazione per il tipo.
tinyness_before Verifica se un tipo può stabilire che un valore è troppo piccolo per essere rappresentato come un valore normalizzato prima dell'arrotondamento.
traps Verifica se la registrazione che segnala le eccezioni aritmetiche è implementata per un tipo.

denorm_min

Restituisce il più piccolo valore denormalizzato diverso da zero.

static constexpr Type denorm_min() throw();

Valore restituito

Il più piccolo valore denormalizzato diverso da zero.

Osservazioni:

long double è uguale a quello double del compilatore C++.

La funzione restituisce il valore minimo per il tipo, uguale a min se has_denorm non è uguale a denorm_present.

Esempio

// 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

Cifre

Restituisce il numero di cifre radice che il tipo può rappresentare senza perdita di precisione.

static constexpr int digits = 0;

Valore restituito

Numero di cifre radice che il tipo può rappresentare senza perdita di precisione.

Osservazioni:

Il membro archivia il numero di cifre radice che il tipo può rappresentare senza modifiche, ovvero il numero di bit diverso da qualsiasi bit più significativo per un tipo Integer predefinito oppure il numero di cifre mantissa per un tipo a virgola mobile predefinito.

Esempio

// 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

Restituisce il numero di cifre decimali che il tipo può rappresentare senza perdita di precisione.

static constexpr int digits10 = 0;

Valore restituito

Numero di cifre decimali che il tipo può rappresentare senza perdita di precisione.

Esempio

// 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

La funzione restituisce la differenza tra 1 e il valore più piccolo maggiore di 1 rappresentabile per il tipo di dati.

static constexpr Type epsilon() throw();

Valore restituito

Differenza tra 1 e il valore più piccolo maggiore di 1 rappresentabile per il tipo di dati.

Osservazioni:

Il valore è FLT_EPSILON per il tipo float. epsilon per un tipo è il più piccolo numero positivo a virgola mobile N tale che N + epsilon + N è rappresentabile.

Esempio

// 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

Verifica se un tipo consente valori denormalizzati.

static constexpr float_denorm_style has_denorm = denorm_absent;

Valore restituito

Valore di enumerazione di tipo const float_denorm_style, che indica se il tipo consente valori denormalizzati.

Osservazioni:

Il membro archivia denorm_present per un tipo a virgola mobile con valori denormalizzati, in modo efficace un numero variabile di bit esponenti.

Esempio

// 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

Verifica se la perdita di precisione viene rilevata come una perdita di denormalizzazione anziché come un risultato inesatto.

static constexpr bool has_denorm_loss = false;

Valore restituito

true se la perdita di accuratezza viene rilevata come perdita di denormalizzazione; false in caso contrario.

Osservazioni:

Il membro archivia true per un tipo che determina se un valore ha perso precisione perché viene fornito come risultato denormalizzato (troppo piccolo per essere rappresentato come un valore normalizzato) o perché è inesatto (non è lo stesso, di conseguenza non è soggetto alla precisione e alle limitazioni dell'intervallo di esponenti), un'opzione con le rappresentazioni a virgola mobile IEC 559 che possono influenzare alcuni risultati.

Esempio

// 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

Verifica se un tipo dispone di una rappresentazione per un numero infinito positivo.

static constexpr bool has_infinity = false;

Valore restituito

true se il tipo ha una rappresentazione per infinito positivo; false in caso contrario.

Osservazioni:

Il membro restituisce true se is_iec559 è true.

Esempio

// 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

Verifica se un tipo dispone di una rappresentazione per un valore diverso da un numero (NaN) non interattivo, che è senza segnalazione.

static constexpr bool has_quiet_NaN = false;

Valore restituito

true se il tipo ha una rappresentazione per una nanna non interattiva; false in caso contrario.

Osservazioni:

Un numero (NaN) non interattivo è una codifica di un valore NaN, che non ne indica la presenza in un'espressione. Il valore restituito è true se is_iec559 è true.

Esempio

// 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

Verifica se un tipo dispone di una rappresentazione per un valore diverso da un numero (NaN) con segnalazione.

static constexpr bool has_signaling_NaN = false;

Valore restituito

true se il tipo ha una rappresentazione per una nan di segnalazione; false in caso contrario.

Osservazioni:

Un numero (NaN) con segnalazione è una codifica di un valore NaN, che ne indica la presenza in un'espressione. Il valore restituito è true se is_iec559 è true.

Esempio

// 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

Rappresentazione di un numero infinito positivo per un tipo, se disponibile.

static constexpr Type infinity() throw();

Valore restituito

Rappresentazione di un numero infinito positivo per un tipo, se disponibile.

Osservazioni:

Il valore restituito è significativo solo se has_infinity è true.

Esempio

// 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

Verifica se il set di valori che può rappresentare è finito.

static constexpr bool is_bounded = false;

Valore restituito

true se il tipo ha un set delimitato di valori rappresentabili; false in caso contrario.

Osservazioni:

Tutti i tipi predefiniti hanno un set delimitato di valori rappresentabili e restituiscono true.

Esempio

// 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

Verifica se i calcoli eseguiti su un tipo sono privi di errori di arrotondamento.

static constexpr bool is_exact = false;

Valore restituito

true se i calcoli sono privi di errori di arrotondamento; false in caso contrario.

Osservazioni:

Tutti i tipi integer predefiniti hanno rappresentazioni esatte per i relativi valori e restituiscono false. Anche una rappresentazione a virgola fissa o razionale è considerata esatta, al contrario di una rappresentazione a virgola mobile.

Esempio

// 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

Verifica se un tipo è conforme agli standard IEC 559.

static constexpr bool is_iec559 = false;

Valore restituito

true se il tipo è conforme agli standard IEC 559; false in caso contrario.

Osservazioni:

Lo standard IEC 559 è uno standard internazionale per la rappresentazione di valori a virgola mobile e negli Stati Uniti è noto anche come IEEE 754.

Esempio

// 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

Verifica se un tipo ha una rappresentazione in forma di Integer.

static constexpr bool is_integer = false;

Valore restituito

true se il tipo ha una rappresentazione integer; false in caso contrario.

Osservazioni:

Tutti i tipi Integer predefiniti hanno una rappresentazione esatta.

Esempio

// 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

Verifica se un tipo ha una rappresentazione in forma di modulo.

static constexpr bool is_modulo = false;

Valore restituito

true se il tipo ha una rappresentazione modulo; false in caso contrario.

Osservazioni:

Una rappresentazione in forma di modulo è una rappresentazione in cui tutti i risultati vengono ridotti in forma di modulo. Tutti i tipi Integer senza segno predefiniti hanno una rappresentazione in forma di modulo.

Esempio

// 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

Verifica se un tipo ha una rappresentazione firmata.

static constexpr bool is_signed = false;

Valore restituito

true se il tipo ha una rappresentazione firmata; false in caso contrario.

Osservazioni:

Il membro archivia true per un tipo che ha una rappresentazione firmata, ovvero per tutti i tipi Integer con segno e a virgola mobile predefiniti.

Esempio

// 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

Verifica se un tipo ha una specializzazione esplicita definita nel modello numeric_limitsdi classe .

static constexpr bool is_specialized = false;

Valore restituito

true se il tipo ha una specializzazione esplicita definita nel modello di classe; false in caso contrario.

Osservazioni:

Tutti i tipi scalari diversi dai puntatori hanno una specializzazione esplicita definita per il modello numeric_limitsdi classe .

Esempio

// 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

Livello più basso

Restituisce il valore finito più negativo.

static constexpr Type lowest() throw();

Valore restituito

Restituisce il valore finito più negativo.

Osservazioni:

Restituisce il valore finito più negativo per il tipo (che è in genere min() per i tipi Integer e -max() per i tipi a virgola mobile). Il valore restituito è significativo se is_bounded è true.

max

Restituisce il valore massimo finito per un tipo.

static constexpr Type max() throw();

Valore restituito

Valore massimo finito per un tipo.

Osservazioni:

Il valore finito massimo è INT_MAX per il tipo int e FLT_MAX per il tipo float. Il valore restituito è significativo se is_bounded è true.

Esempio

// 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

Restituisce il numero di cifre decimali richiesto per garantire che due valori distinti del tipo abbiano rappresentazioni decimali distinte.

static constexpr int max_digits10 = 0;

Valore restituito

Restituisce il numero di cifre decimali richiesto per garantire che due valori distinti del tipo abbiano rappresentazioni decimali distinte.

Osservazioni:

Il membro archivia il numero di cifre decimali richiesto per garantire che due valori distinti del tipo abbiano rappresentazioni decimali distinte.

max_exponent

Restituisce l'esponente integrale positivo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di radice è elevata a tale potenza.

static constexpr int max_exponent = 0;

Valore restituito

Esponente integrale massimo basato su radice che il tipo può rappresentare.

Osservazioni:

La funzione membro restituita è significativa solo per i tipi a virgola mobile. max_exponent è il valore FLT_MAX_EXP per il tipo float.

Esempio

// 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

Restituisce l'esponente integrale positivo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di dieci è elevata a tale potenza.

static constexpr int max_exponent10 = 0;

Valore restituito

Esponente in base 10 integrale massimo che il tipo può rappresentare.

Osservazioni:

La funzione membro restituita è significativa solo per i tipi a virgola mobile. max_exponent è il valore FLT_MAX_10 per il tipo float.

Esempio

// 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

min

Restituisce il valore normalizzato minimo per un tipo.

static constexpr Type min() throw();

Valore restituito

Valore normalizzato minimo per il tipo.

Osservazioni:

Il valore normalizzato minimo è INT_MIN per il tipo int e FLT_MIN per il tipo float. Il valore restituito è significativo se is_bounded è true o se is_signed è false.

Esempio

// 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

Restituisce l'esponente integrale negativo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di radice è elevata a tale potenza.

static constexpr int min_exponent = 0;

Valore restituito

Esponente integrale minimo basato su radice che il tipo può rappresentare.

Osservazioni:

La funzione membro è significativa solo per i tipi a virgola mobile. min_exponent è il valore FLT_MIN_EXP per il tipo float.

Esempio

// 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

Restituisce l'esponente integrale negativo massimo che il tipo a virgola mobile può rappresentare come un valore finito quando una base di dieci è elevata a tale potenza.

static constexpr int min_exponent10 = 0;

Valore restituito

Esponente in base 10 integrale minimo che il tipo può rappresentare.

Osservazioni:

La funzione membro è significativa solo per i tipi a virgola mobile. min_exponent10 è il valore FLT_MIN_10_EXP per il tipo float.

Esempio

// 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

Restituisce la rappresentazione di un valore diverso da un numero (NaN) non interattivo per il tipo.

static constexpr Type quiet_NaN() throw();

Valore restituito

Rappresentazione di un numero (NaN) non interattivo per il tipo.

Osservazioni:

Il valore restituito è significativo solo se has_quiet_NaN è true.

Esempio

// 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

Restituisce la base integrale, detta radice, usata per la rappresentazione di un tipo.

static constexpr int radix = 0;

Valore restituito

Base integrale per la rappresentazione del tipo.

Osservazioni:

La base è 2 per i tipi Integer predefiniti e la base a cui viene elevato l'esponente, o FLT_RADIX, per i tipi a virgola mobile predefiniti.

Esempio

// 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

Restituisce il valore massimo per il tipo di errore di arrotondamento.

static constexpr Type round_error() throw();

Valore restituito

Errore massimo di arrotondamento per il tipo.

Esempio

// 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

Restituisce un valore che descrive i vari metodi che un'implementazione può scegliere per l'arrotondamento di un valore a virgola mobile in un valore intero.

static constexpr float_round_style round_style = round_toward_zero;

Valore restituito

Valore dell'enumerazione float_round_style che descrive lo stile di arrotondamento.

Osservazioni:

Il membro archivia un valore che descrive i vari metodi che un'implementazione può scegliere per l'arrotondamento di un valore a virgola mobile in un valore integer.

Lo stile di arrotondamento è hardcoded in questa implementazione, perciò anche se il programma viene avviato con una diversa modalità di arrotondamento, tale valore non verrà modificato.

Esempio

// 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

Restituisce la rappresentazione di un valore diverso da un numero (NaN) con segnalazione per il tipo.

static constexpr Type signaling_NaN() throw();

Valore restituito

Rappresentazione di un numero (NaN) non con segnalazione per il tipo.

Osservazioni:

Il valore restituito è significativo solo se has_signaling_NaN è true.

Esempio

// 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

Verifica se un tipo può stabilire che un valore è troppo piccolo per essere rappresentato come un valore normalizzato prima dell'arrotondamento.

static constexpr bool tinyness_before = false;

Valore restituito

true se il tipo è in grado di rilevare valori di piccole dimensioni prima dell'arrotondamento; in caso contrario, false.

Osservazioni:

I tipi in grado di rilevare valori di piccole dimensioni erano inclusi come opzione con le rappresentazioni IEC 559 a virgola mobile e la relativa implementazione può influenzare alcuni risultati.

Esempio

// 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

Verifica se la registrazione che segnala le eccezioni aritmetiche è implementata per un tipo.

static constexpr bool traps = false;

Valore restituito

true se l'intercettazione viene implementata per il tipo; false se non lo è.

Esempio

// 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