numeric_limits (clase)

La plantilla de clase describe las propiedades aritméticas de los tipos numéricos integrados.

Sintaxis

template <class Type>
    class numeric_limits

Parámetros

Tipo
Tipo de datos del elemento fundamental cuyas propiedades se están probando, consultando o estableciendo. Type se puede declarar también con const, volatile, o const volatile.

Comentarios

El encabezado define especializaciones explícitas para los 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 y char32_t. Para estas especializaciones explícitas, el miembro numeric_limits::is_specialized es truey todos los miembros pertinentes tienen valores significativos. El programa puede proporcionar especializaciones explícitas adicionales. La mayoría de las funciones miembro de la clase describen o prueban implementaciones posibles de float.

Para una especialización arbitraria, ningún miembro tiene valores significativos. Un objeto de miembro que no tiene un valor significativo almacena cero (o false) y una función miembro que no devuelve un valor significativo devuelve Type(0).

Constantes y funciones estáticas

Nombre Descripción
denorm_min Devuelve el valor más pequeño distinto de cero desnormalizado.
digits Devuelve el número de dígitos de base que el tipo puede representar sin pérdida de precisión.
digits10 Devuelve el número de dígitos decimales que el tipo puede representar sin pérdida de precisión.
epsilon Devuelve la diferencia entre 1 y el valor más pequeño mayor que 1, que el tipo de datos puede representar.
has_denorm Comprueba si un tipo permite valores no normalizados.
has_denorm_loss Comprueba si se detecta la pérdida de precisión como una pérdida de desnormalización en lugar de como un resultado inexacto.
has_infinity Comprueba si un tipo tiene una representación de infinito positivo.
has_quiet_NaN Comprueba si un tipo tiene una representación para un NaN (no es un número) silencioso, que no es de señalización.
has_signaling_NaN Comprueba si un tipo tiene una representación para un NaN (no es un número) de señalización.
infinity Representación de infinito positivo de un tipo, si está disponible.
is_bounded Comprueba si el conjunto de valores que un tipo puede representar es finito.
is_exact Comprueba si los cálculos realizados en un tipo están libres de errores de redondeo.
is_iec559 Comprueba si un tipo se ajusta a los estándares IEC 559.
is_integer Comprueba si un tipo tiene una representación de entero.
is_modulo Comprueba si un tipo tiene una representación de módulo.
is_signed Comprueba si un tipo tiene una representación con signo.
is_specialized Comprueba si un tipo tiene una especialización explícita definida en la plantilla de clase numeric_limits.
lowest Devuelve el mayor valor finito negativo.
max Devuelve el valor finito máximo para un tipo.
max_digits10 Devuelve el número de dígitos decimales necesarios para asegurarse de que dos valores distintos del tipo tengan distintas representaciones decimales.
max_exponent Devuelve el exponente integral positivo máximo que el tipo de punto flotante puede representar como valor finito cuando se eleva una base de base a esa potencia.
max_exponent10 Devuelve el exponente integral positivo máximo que puede representar el tipo de punto flotante como valor finito cuando se eleva una base de diez a esa potencia.
min Devuelve el valor normalizado mínimo para un tipo.
min_exponent Devuelve el exponente integral negativo máximo que puede representar el tipo de punto flotante como valor finito cuando se eleva una base de base a esa potencia.
min_exponent10 Devuelve el exponente integral negativo máximo que puede representar el tipo de punto flotante como valor finito cuando se eleva una base de diez a esa potencia.
quiet_NaN Devuelve la representación de un NaN (no es un número) silencioso para el tipo.
radix Devuelve la base integral, llamada base, usada para la representación de un tipo.
round_error Devuelve el error de redondeo máximo para el tipo.
round_style Devuelve un valor que describe los diversos métodos que una implementación puede elegir para redondear un valor de punto flotante a un valor entero.
signaling_NaN Devuelve la representación de un NaN (no es un número) de señalización para el tipo.
tinyness_before Comprueba si un tipo puede determinar que un valor es demasiado pequeño para representarse como un valor normalizado antes de redondearlo.
traps Comprueba si la captura que informa sobre excepciones aritméticas está implementada para un tipo.

denorm_min

Devuelve el valor más pequeño distinto de cero desnormalizado.

static constexpr Type denorm_min() throw();

Valor devuelto

El valor más pequeño distinto de cero desnormalizado.

Comentarios

long double es igual que double para el compilador de C++.

La función devuelve el valor mínimo para el tipo, que es el mismo que min si has_denorm no es igual a denorm_present.

Ejemplo

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

Devuelve el número de dígitos de base que el tipo puede representar sin pérdida de precisión.

static constexpr int digits = 0;

Valor devuelto

El número de dígitos de base que el tipo puede representar sin pérdida de precisión.

Comentarios

El miembro almacena el número de dígitos de base que el tipo puede representar sin cambiar, que es el número de bits además de cualquier bit de signo para un tipo entero predefinido, o el número de dígitos de mantisa para un tipo de punto flotante predefinido.

Ejemplo

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

Devuelve el número de dígitos decimales que el tipo puede representar sin pérdida de precisión.

static constexpr int digits10 = 0;

Valor devuelto

El número de dígitos decimales que el tipo puede representar sin pérdida de precisión.

Ejemplo

// 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 función devuelve la diferencia entre 1 y el valor más pequeño mayor que 1, que el tipo de datos puede representar.

static constexpr Type epsilon() throw();

Valor devuelto

La diferencia entre 1 y el valor más pequeño mayor que 1, que el tipo de datos puede representar.

Comentarios

El valor es FLT_EPSILON para el tipo float. epsilon para un tipo es el número N de punto flotante positivo más pequeño de manera que N + epsilon + N se pueda representar.

Ejemplo

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

Comprueba si un tipo permite valores no normalizados.

static constexpr float_denorm_style has_denorm = denorm_absent;

Valor devuelto

Un valor de enumeración de tipo const float_denorm_style, que indica si el tipo permite valores desnormalizados.

Comentarios

El miembro almacena denorm_present para un tipo de punto flotante que tiene valores desnormalizados, de manera eficaz, un número variable de bits de exponente.

Ejemplo

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

Comprueba si se detecta la pérdida de precisión como una pérdida de desnormalización en lugar de como un resultado inexacto.

static constexpr bool has_denorm_loss = false;

Valor devuelto

true si se detecta la pérdida de precisión como una pérdida de desnormalización; false si no es así.

Comentarios

El miembro almacena True para un tipo que determina si un valor ha perdido precisión porque se entrega como un resultado desnormalizado (demasiado pequeño para representarse como un valor normalizado) o porque no es exacto (no es igual que un resultado no sujeto a las limitaciones de intervalo de exponente y precisión), una opción con representaciones de punto flotante IEC 559 que puede afectar a algunos resultados.

Ejemplo

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

Comprueba si un tipo tiene una representación de infinito positivo.

static constexpr bool has_infinity = false;

Valor devuelto

true si el tipo tiene una representación de infinito positivo; false si no es así.

Comentarios

El miembro devuelve true si is_iec559 es true.

Ejemplo

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

Comprueba si un tipo tiene una representación para un NaN (no es un número) silencioso, que no sea de señalización.

static constexpr bool has_quiet_NaN = false;

Valor devuelto

true si el tipo tiene una representación para un NaN silencioso; false si no es así.

Comentarios

Un NaN silencioso es una codificación, para no es un número, que no indica su presencia en una expresión. El valor devuelto es true si is_iec559 es True.

Ejemplo

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

Comprueba si un tipo tiene una representación para un NaN (no es un número) de señalización.

static constexpr bool has_signaling_NaN = false;

Valor devuelto

true si el tipo tiene una representación para un NAN de señalización; false si no es así.

Comentarios

Un NaN de señalización es una codificación, para no es un número, que indica su presencia en una expresión. El valor devuelto es true si is_iec559 es True.

Ejemplo

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

La representación de infinito positivo de un tipo, si está disponible.

static constexpr Type infinity() throw();

Valor devuelto

La representación de infinito positivo de un tipo, si está disponible.

Comentarios

El valor devuelto solo es significativo si has_infinity es true.

Ejemplo

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

Comprueba si el conjunto de valores que un tipo puede representar es finito.

static constexpr bool is_bounded = false;

Valor devuelto

true si el tipo tiene un conjunto limitado de valores representables; false si no es así.

Comentarios

Todos los tipos predefinidos tienen un conjunto limitado de valores representables y devuelven true.

Ejemplo

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

Comprueba si los cálculos realizados en un tipo están libres de errores de redondeo.

static constexpr bool is_exact = false;

Valor devuelto

true si los cálculos están libres de errores de redondeo; false si no es así.

Comentarios

Todos los tipos de enteros predefinidos tienen representaciones exactas para sus valores y devuelven false. Un punto fijo o una representación racional también se considera exacta, pero una representación de punto flotante no lo es.

Ejemplo

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

Comprueba si un tipo se ajusta a los estándares IEC 559.

static constexpr bool is_iec559 = false;

Valor devuelto

true si el tipo se ajusta a los estándares IEC 559; false si no es así.

Comentarios

IEC 559 es un estándar internacional para representar valores de punto flotante y también se conoce como IEEE 754 en EE. UU.

Ejemplo

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

Comprueba si un tipo tiene una representación de entero.

static constexpr bool is_integer = false;

Valor devuelto

true si el tipo tiene una representación de entero; false si no es así.

Comentarios

Todos los tipos de entero predefinidos tienen una representación de entero.

Ejemplo

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

Comprueba si un tipo tiene una representación de módulo.

static constexpr bool is_modulo = false;

Valor devuelto

true si el tipo tiene una representación de módulo; false si no es así.

Comentarios

Una representación de módulo es una representación donde todos los resultados son valores de módulo reducidos. Todos los tipos de entero sin signo predefinidos tienen una representación de módulo.

Ejemplo

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

Comprueba si un tipo tiene una representación con signo.

static constexpr bool is_signed = false;

Valor devuelto

true si el tipo tiene una representación con signo; false si no es así.

Comentarios

El miembro almacena True para un tipo que tiene una representación con signo, que es el caso de todos los tipos de entero con signo y de punto flotante predefinidos.

Ejemplo

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

Comprueba si un tipo tiene una especialización explícita definida en la plantilla de clase numeric_limits.

static constexpr bool is_specialized = false;

Valor devuelto

true si el tipo tiene una especialización explícita definida en la plantilla de clase; false si no es así.

Comentarios

Todos los tipos escalares distintos a los punteros tienen una especialización explícita definida para la plantilla de clase numeric_limits.

Ejemplo

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

más bajo

Devuelve el mayor valor finito negativo.

static constexpr Type lowest() throw();

Valor devuelto

Devuelve el mayor valor finito negativo.

Comentarios

Devuelve el mayor valor finito negativo para el tipo (que suele ser min() para los tipos enteros y -max() para los tipos de punto flotante). El valor devuelto es significativo si is_bounded es true.

max

Devuelve el valor finito máximo para un tipo.

static constexpr Type max() throw();

Valor devuelto

El valor finito máximo para un tipo.

Comentarios

El valor finito máximo es INT_MAX para el tipo int y FLT_MAX para el tipo float. El valor devuelto es significativo si is_bounded es true.

Ejemplo

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

Devuelve el número de dígitos decimales necesarios para asegurarse de que dos valores distintos del tipo tengan distintas representaciones decimales.

static constexpr int max_digits10 = 0;

Valor devuelto

Devuelve el número de dígitos decimales necesarios para asegurarse de que dos valores distintos del tipo tengan distintas representaciones decimales.

Comentarios

El miembro almacena el número de dígitos decimales necesarios para asegurarse de que dos valores distintos del tipo tengan distintas representaciones decimales.

max_exponent

Devuelve el exponente integral positivo máximo que el tipo de punto flotante puede representar como valor finito cuando se eleva una base de base a esa potencia.

static constexpr int max_exponent = 0;

Valor devuelto

El máximo exponente basado en la base integral que se representa mediante el tipo.

Comentarios

El valor devuelto de la función miembro es significativo solo para los tipos de punto flotante. El max_exponent es el valor FLT_MAX_EXP para el tipo float.

Ejemplo

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

Devuelve el exponente integral positivo máximo que puede representar el tipo de punto flotante como valor finito cuando se eleva una base de diez a esa potencia.

static constexpr int max_exponent10 = 0;

Valor devuelto

El máximo exponente de base 10 integral que se representa mediante el tipo.

Comentarios

El valor devuelto de la función miembro es significativo solo para los tipos de punto flotante. El max_exponent es el valor FLT_MAX_10 para el tipo float.

Ejemplo

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

Devuelve el valor normalizado mínimo para un tipo.

static constexpr Type min() throw();

Valor devuelto

El valor normalizado mínimo para el tipo.

Comentarios

El valor normalizado mínimo es INT_MIN para el tipo int y FLT_MIN para el tipo float. El valor devuelto es significativo si is_bounded es true o si is_signed es false.

Ejemplo

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

Devuelve el exponente integral negativo máximo que puede representar el tipo de punto flotante como valor finito cuando se eleva una base de base a esa potencia.

static constexpr int min_exponent = 0;

Valor devuelto

El mínimo exponente basado en la base integral que se representa mediante el tipo.

Comentarios

La función miembro es significativa solo para los tipos de punto flotante. El min_exponent es el valor FLT_MIN_EXP para el tipo float.

Ejemplo

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

Devuelve el exponente integral negativo máximo que puede representar el tipo de punto flotante como valor finito cuando se eleva una base de diez a esa potencia.

static constexpr int min_exponent10 = 0;

Valor devuelto

El mínimo exponente de base 10 integral que se representa mediante el tipo.

Comentarios

La función miembro es significativa solo para los tipos de punto flotante. El min_exponent10 es el valor FLT_MIN_10_EXP para el tipo float.

Ejemplo

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

Devuelve la representación de un NaN (no es un número) silencioso para el tipo.

static constexpr Type quiet_NaN() throw();

Valor devuelto

La representación de un NaN silencioso para el tipo.

Comentarios

El valor devuelto solo es significativo si has_quiet_NaN es true.

Ejemplo

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

Devuelve la base integral, llamada base, usada para la representación de un tipo.

static constexpr int radix = 0;

Valor devuelto

La base integral para la representación del tipo.

Comentarios

La base es 2 para los tipos enteros predefinidos, y la base a la que se eleva el exponente, o FLT_RADIX, para los tipos de punto flotante predefinidos.

Ejemplo

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

Devuelve el error de redondeo máximo para el tipo.

static constexpr Type round_error() throw();

Valor devuelto

El error de redondeo máximo para el tipo.

Ejemplo

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

Devuelve un valor que describe los diversos métodos que una implementación puede elegir para redondear un valor de punto flotante a un valor entero.

static constexpr float_round_style round_style = round_toward_zero;

Valor devuelto

Un valor de la enumeración float_round_style que describe el estilo de redondeo.

Comentarios

El miembro almacena un valor que describe los diversos métodos que una implementación puede elegir para redondear un valor de punto flotante a un valor entero.

El estilo de redondeo está codificado de forma rígida en esta implementación, por lo que aunque el programa se inicie con un modo de redondeo diferente, el valor no cambiará.

Ejemplo

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

Devuelve la representación de un NaN (no es un número) de señalización para el tipo.

static constexpr Type signaling_NaN() throw();

Valor devuelto

La representación de un NaN de señalización para el tipo.

Comentarios

El valor devuelto solo es significativo si has_signaling_NaN es true.

Ejemplo

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

Comprueba si un tipo puede determinar que un valor es demasiado pequeño para representarse como un valor normalizado antes de redondearlo.

static constexpr bool tinyness_before = false;

Valor devuelto

true si el tipo puede detectar valores muy pequeños antes del redondeo; false si no puede.

Comentarios

Los tipos que pueden detectar valores tinyness se han incluido como una opción con las representaciones de punto flotante IEC 559 y su implementación puede afectar a algunos resultados.

Ejemplo

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

Comprueba si la captura que informa sobre excepciones aritméticas está implementada para un tipo.

static constexpr bool traps = false;

Valor devuelto

true si se implementa la captura para el tipo; false si no es así.

Ejemplo

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