Classe numeric_limits

O modelo de classe descreve propriedades aritméticas de tipos numéricos internos.

Sintaxe

template <class Type>
    class numeric_limits

Parâmetros

Tipo
O tipo de dados do elemento fundamental cujas propriedades estão sendo testadas ou consultadas ou definidas. Tipo também pode ser declarado const, volatile ou const volatile.

Comentários

O cabeçalho define as especializações explícitas para os tipos wchar_t, bool, char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, long double, long long, unsigned long long, char16_t e char32_t. Para essas especializações explícitas, o membro numeric_limits::is_specialized é true e todos os membros relevantes têm valores significativos. O programa pode fornecer especializações explícitas adicionais. A maioria das funções membro da classe descreve ou testa possíveis implementações de float.

Para uma especialização arbitrária, nenhum membro tem valores significativos. Um objeto membro que não tem um valor significativo armazena zero (ou false) e retorna uma função membro que não retorna um valor significativo Type(0).

Constantes e funções estáticas

Nome Descrição
denorm_min Retorna o menor valor desnormalizado diferente de zero.
digits Retorna o número de dígitos de base que o tipo pode representar sem perda de precisão.
digits10 Retorna o número de dígitos decimais que o tipo pode representar sem perda de precisão.
epsilon Retorna a diferença entre 1 e o menor valor maior que 1 que o tipo de dados pode representar.
has_denorm Testa se um tipo permite valores desnormalizados.
has_denorm_loss Testa se a perda de precisão é detectada como uma perda de desnormalização em vez de um resultado inexato.
has_infinity Testa se um tipo tem uma representação de infinito positivo.
has_quiet_NaN Testa se um tipo tem uma representação de um silencioso NAN (não é um número), que é sem sinal.
has_signaling_NaN Testa se um tipo tem uma representação para não sinalizar um número (NAN).
infinity A representação de infinito positivo para um tipo, se disponível.
is_bounded Testa se o conjunto de valores que um tipo pode representar é finito.
is_exact Testa se os cálculos feitos em um tipo estão livres de erros de arredondamento.
is_iec559 Testa se um tipo está em conformidade com os padrões IEC 559.
is_integer Testa se um tipo tem uma representação de inteiro.
is_modulo Testa se um tipo tem uma representação de módulo.
is_signed Testa se um tipo tem uma representação com sinal.
is_specialized Testa se um tipo tem uma especialização explícita definida no modelo de classe numeric_limits.
lowest Retorna o valor finito mais negativo.
max Retorna o valor máximo finito para um tipo.
max_digits10 Retorna o número de dígitos decimais necessários para garantir que dois valores distintos do tipo tenham diferentes representações decimais.
max_exponent Retorna o expoente integral positivo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de base é elevada a essa potência.
max_exponent10 Retorna o expoente integral positivo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de dez é elevada a essa potência.
min Retorna o valor normalizado mínimo para um tipo.
min_exponent Retorna o expoente integral negativo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de base é elevada a essa potência.
min_exponent10 Retorna o expoente integral negativo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de dez é elevada a essa potência.
quiet_NaN Retorna a representação de um NAN (não é um número) silencioso para o tipo.
radix Retorna a base integral, conhecida como base, usada para a representação de um tipo.
round_error Retorna o erro de arredondamento máximo para o tipo.
round_style Retorna um valor que descreve os vários métodos que uma implementação pode escolher para o arredondamento de um valor de ponto flutuante para um valor inteiro.
signaling_NaN Retorna a representação de um sinal NAN (não é um número) para o tipo.
tinyness_before Testa se um tipo pode determinar que um valor é muito pequeno para representar como um valor normalizado antes de arredondá-lo.
traps Testa se o trapping que relata exceções aritméticas é implementada para um tipo.

denorm_min

Retorna o menor valor desnormalizado diferente de zero.

static constexpr Type denorm_min() throw();

Valor de Devolução

O menor valor desnormalizado diferente de zero.

Comentários

long double é o mesmo que double para o compilador C++.

A função retornará o valor mínimo para o tipo, que é o mesmo que min se has_denorm não for igual a denorm_present.

Exemplo

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

dígitos

Retorna o número de dígitos de base que o tipo pode representar sem perda de precisão.

static constexpr int digits = 0;

Valor de Devolução

O número de dígitos de base que o tipo pode representar sem perda de precisão.

Comentários

O membro armazena o número de dígitos de base que o tipo pode representar sem alteração, que é o número de bits diferente de qualquer bit de sinal para um tipo inteiro predefinido ou o número de dígitos de mantissa para um tipo de ponto flutuante predefinido.

Exemplo

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

Retorna o número de dígitos decimais que o tipo pode representar sem perda de precisão.

static constexpr int digits10 = 0;

Valor de Devolução

O número de dígitos decimais que o tipo pode representar sem perda de precisão.

Exemplo

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

épsilon

A função retorna a diferença entre 1 e o menor valor maior que 1 que é representável para o tipo de dados.

static constexpr Type epsilon() throw();

Valor de Devolução

A diferença entre 1 e o menor valor maior que 1 que é representável para o tipo de dados.

Comentários

O valor é FLT_EPSILON para o tipo float. epsilon para um tipo é o menor número de ponto flutuante positivo N que N + epsilon + N é representável.

Exemplo

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

Testa se um tipo permite valores desnormalizados.

static constexpr float_denorm_style has_denorm = denorm_absent;

Valor de Devolução

Um valor de enumeração do tipo const float_denorm_style, indicando se o tipo permite valores desnormalizados.

Comentários

Os repositórios do membro denorm_present para um tipo de ponto flutuante com valores desnormalizados, efetivamente um número variável de bits exponenciais.

Exemplo

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

Testa se a perda de precisão é detectada como uma perda de desnormalização em vez de um resultado inexato.

static constexpr bool has_denorm_loss = false;

Valor de Devolução

true se a perda de precisão for detectada como uma perda de desnormalização; false se não for.

Comentários

O membro armazena true para um tipo que determina se um valor perdeu a precisão porque foi entregue como um resultado desnormalizado (muito pequeno para ser representado como um valor normalizado) ou porque está inexato (não o mesmo por não estar sujeito a limitações de intervalo exponencial e precisão), uma opção com representações de ponto flutuantes IEC 559 que pode afetar alguns resultados.

Exemplo

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

Testa se um tipo tem uma representação de infinito positivo.

static constexpr bool has_infinity = false;

Valor de Devolução

true se o tipo tiver uma representação de infinito positivo; false se não tiver.

Comentários

O membro retornará true se is_iec559 for true.

Exemplo

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

Testa se um tipo tem uma representação de um silencioso NAN (não é um número), que é sem sinal.

static constexpr bool has_quiet_NaN = false;

Valor de Devolução

true se o tipo tiver uma representação de NAN silencioso; false se não tiver.

Comentários

Um NAN silencioso é uma codificação para um não número, o que não indica sua presença em uma expressão. O valor retornado será true se is_iec559 for true.

Exemplo

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

Testa se um tipo tem uma representação para não sinalizar um número (NAN).

static constexpr bool has_signaling_NaN = false;

Valor de Devolução

true se o tipo tiver uma representação de um NAN com sinal; false se não tiver.

Comentários

Um NAN com sinal é uma codificação para um não número, o que indica sua presença em uma expressão. O valor retornado será true se is_iec559 for true.

Exemplo

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

A representação de infinito positivo para um tipo, se disponível.

static constexpr Type infinity() throw();

Valor de Devolução

A representação de infinito positivo para um tipo, se disponível.

Comentários

O valor retornado será significativo somente se has_infinity for true.

Exemplo

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

Testa se o conjunto de valores que um tipo pode representar é finito.

static constexpr bool is_bounded = false;

Valor de Devolução

true se o tipo tiver um conjunto limitado de valores representáveis; false se não tiver.

Comentários

Todos os tipos predefinidos têm um conjunto limitado de valores representáveis e retornam true.

Exemplo

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

Testa se os cálculos feitos em um tipo estão livres de erros de arredondamento.

static constexpr bool is_exact = false;

Valor de Devolução

true se os cálculos estiverem livres de erros de arredondamento; false se não estiverem.

Comentários

Todos os tipos de inteiro predefinidos têm representações exatas para seus valores e retornam false. Uma representação de ponto fixo ou racional também é considerada exata, mas uma representação de ponto flutuante não é.

Exemplo

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

Testa se um tipo está em conformidade com os padrões IEC 559.

static constexpr bool is_iec559 = false;

Valor de Devolução

true se o tipo estiver em conformidade com os padrões IEC 559; false se não estiver.

Comentários

O IEC 559 é um padrão internacional que representa valores de ponto flutuante e também é conhecido como IEEE 754 nos EUA.

Exemplo

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

Testa se um tipo tem uma representação de inteiro.

static constexpr bool is_integer = false;

Valor de Devolução

true se o tipo tiver uma representação de inteiro; false se não tiver.

Comentários

Todos os tipos de inteiro predefinidos têm uma representação de inteiro.

Exemplo

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

Testa se um tipo tem uma representação de módulo.

static constexpr bool is_modulo = false;

Valor de Devolução

true se o tipo tiver uma representação de módulo; false se não tiver.

Comentários

Uma representação de módulo é uma representação na qual todos os resultados são reduzidos a um módulo de algum valor. Todos os tipos de inteiro sem sinal predefinidos têm uma representação de módulo.

Exemplo

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

Testa se um tipo tem uma representação com sinal.

static constexpr bool is_signed = false;

Valor de Devolução

true se o tipo tiver uma representação assinada; false se não tiver.

Comentários

O membro armazena true para um tipo que tem uma representação com sinal, que é o caso para todos os tipos de inteiros com sinal e de ponto flutuante predefinidos.

Exemplo

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

Testa se um tipo tem uma especialização explícita definida no modelo de classe numeric_limits.

static constexpr bool is_specialized = false;

Valor de Devolução

true se um tipo tiver uma especialização explícita definida no modelo de classe; false se não tiver.

Comentários

Todos os tipos escalares, exceto ponteiros, têm uma especialização explícita definida para o modelo de classe numeric_limits.

Exemplo

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

mais baixo

Retorna o valor finito mais negativo.

static constexpr Type lowest() throw();

Valor de Devolução

Retorna o valor finito mais negativo.

Comentários

Retorna o valor finito mais negativo para o tipo (que geralmente é min() para tipos de inteiro e -max() para tipos de ponto flutuante). O valor de retorno será significativo se is_bounded for true.

max

Retorna o valor máximo finito para um tipo.

static constexpr Type max() throw();

Valor de Devolução

O valor máximo finito para um tipo.

Comentários

O valor máximo finito é INT_MAX para o tipo int e FLT_MAX para o tipo float. O valor retornado será significativo se is_bounded for true.

Exemplo

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

Retorna o número de dígitos decimais necessários para garantir que dois valores distintos do tipo tenham diferentes representações decimais.

static constexpr int max_digits10 = 0;

Valor de Devolução

Retorna o número de dígitos decimais necessários para garantir que dois valores distintos do tipo tenham diferentes representações decimais.

Comentários

O membro armazena o número de dígitos decimais necessários para garantir que dois valores distintos do tipo tenham diferentes representações decimais.

max_exponent

Retorna o expoente integral positivo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de base é elevada a essa potência.

static constexpr int max_exponent = 0;

Valor de Devolução

O expoente com base integral máximo representável pelo tipo.

Comentários

O retorno da função membro é significativo apenas para os tipos de ponto flutuante. O max_exponent é o valor FLT_MAX_EXP para o tipo float.

Exemplo

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

Retorna o expoente integral positivo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de dez é elevada a essa potência.

static constexpr int max_exponent10 = 0;

Valor de Devolução

O expoente de base 10 integral máxima representável pelo tipo.

Comentários

O retorno da função membro é significativo apenas para os tipos de ponto flutuante. O max_exponent é o valor FLT_MAX_10 para o tipo float.

Exemplo

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

Retorna o valor normalizado mínimo para um tipo.

static constexpr Type min() throw();

Valor de Devolução

O valor normalizado mínimo para o tipo.

Comentários

O valor normalizado mínimo é INT_MIN para o tipo int e FLT_MIN para o tipo float. O valor retornado será significativo se is_bounded for true ou se is_signed for false.

Exemplo

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

Retorna o expoente integral negativo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de base é elevada a essa potência.

static constexpr int min_exponent = 0;

Valor de Devolução

O expoente com base integral mínima representável pelo tipo.

Comentários

A função membro é significativa apenas para os tipos de ponto flutuante. O min_exponent é o valor FLT_MIN_EXP para o tipo float.

Exemplo

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

Retorna o expoente integral negativo máximo que o tipo de ponto flutuante pode representar como um valor finito quando uma base de dez é elevada a essa potência.

static constexpr int min_exponent10 = 0;

Valor de Devolução

O expoente de base 10 integral mínimo representável pelo tipo.

Comentários

A função membro é significativa apenas para os tipos de ponto flutuante. O min_exponent10 é o valor FLT_MIN_10_EXP para o tipo float.

Exemplo

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

Retorna a representação de um NAN (não é um número) silencioso para o tipo.

static constexpr Type quiet_NaN() throw();

Valor de Devolução

A representação de um NAN silencioso para o tipo.

Comentários

O valor retornado será significativo somente se has_quiet_NaN for true.

Exemplo

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

Retorna a base integral, conhecida como base, usada para a representação de um tipo.

static constexpr int radix = 0;

Valor de Devolução

A base integral para a representação do tipo.

Comentários

A base é 2 para os tipos de inteiro predefinidos e para a base para a qual o expoente é elevado ou FLT_RADIX, para os tipos de pontos flutuantes predefinidos.

Exemplo

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

Retorna o erro de arredondamento máximo para o tipo.

static constexpr Type round_error() throw();

Valor de Devolução

O erro de arredondamento máximo para o tipo.

Exemplo

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

Retorna um valor que descreve os vários métodos que uma implementação pode escolher para o arredondamento de um valor de ponto flutuante para um valor inteiro.

static constexpr float_round_style round_style = round_toward_zero;

Valor de Devolução

Um valor da enumeração float_round_style que descreve o estilo de arredondamento.

Comentários

O membro armazena um valor que descreve os vários métodos que uma implementação pode escolher para o arredondamento de um valor de ponto flutuante para um valor inteiro.

O estilo de arredondamento fixo é nessa implementação. Mesmo que se o programa for iniciado com um modo de arredondamento diferente, esse valor não será alterado.

Exemplo

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

Retorna a representação de um sinal NAN (não é um número) para o tipo.

static constexpr Type signaling_NaN() throw();

Valor de Devolução

A representação de um NAN com sinal para o tipo.

Comentários

O valor retornado será significativo somente se has_signaling_NaN for true.

Exemplo

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

Testa se um tipo pode determinar que um valor é muito pequeno para representar como um valor normalizado antes de arredondá-lo.

static constexpr bool tinyness_before = false;

Valor de Devolução

true se o tipo puder detectar valores pequenos antes do arredondamento; false se não puder.

Comentários

Tipos que podem detectar pequenez foram incluídos como uma opção com representações de pontos flutuantes IEC 559 e sua implementação pode afetar alguns resultados.

Exemplo

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

interceptações

Testa se o trapping que relata exceções aritméticas é implementada para um tipo.

static constexpr bool traps = false;

Valor de Devolução

true se trapping for implementado para o tipo; false se não for.

Exemplo

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