Espacios de nombres
Variantes
Acciones

std::numeric_limits

De cppreference.com
< cpp‎ | types
 
 
Biblioteca de servicios
 
Apoyo de tipos
Tipos básicos
Tipos fundamentales
Tipos enteros de anchura fija (C++11)
Límites numéricos
numeric_limits
Interfaz de C de límites numéricos
Información de tipo
en tiempo de ejecución
Rasgos de tipos
Categorías de tipos
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Propiedades de tipos
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(hasta C++20)
(C++11)(en desuso en C++20)
(C++11)
Constantes de rasgos de tipos
Metafunciones
(C++17)
Contexto de evaluación constante
Operaciones soportadas
Relaciones y consultas de propiedades
Modificaciones de tipos
(C++11)(C++11)(C++11)
Transformaciones de tipos
(C++11)
(C++11)
(C++17)
(C++11)(hasta C++20)(C++17)
 
std::numeric_limits
 
Definido en el archivo de encabezado <limits>
template< class T > class numeric_limits;

La plantilla de clase numeric_limits proporciona una forma estandarizada para consultar las distintas propiedades de los tipos fundamentales (por ejemplo, el mayor valor posible para el tipo int es std::numeric_limits<int>::max()).

Esta información se proporciona a través de especializaciones de la plantilla numeric_limits. La biblioteca estándar hace especializaciones disponibles para todos los tipos fundamentales:

Definido en el archivo de encabezado <limits>
template<> class numeric_limits<bool>;
template<> class numeric_limits<char>;
template<> class numeric_limits<signed char>;
template<> class numeric_limits<unsigned char>;
template<> class numeric_limits<wchar_t>;
template<> class numeric_limits<char8_t>;
(desde C++20)
template<> class numeric_limits<char16_t>;
(desde C++11)
template<> class numeric_limits<char32_t>;
(desde C++11)
template<> class numeric_limits<short>;
template<> class numeric_limits<unsigned short>;
template<> class numeric_limits<int>;
template<> class numeric_limits<unsigned int>;
template<> class numeric_limits<long>;
template<> class numeric_limits<unsigned long>;
template<> class numeric_limits<long long>;
(desde C++11)
template<> class numeric_limits<unsigned long long>;
(desde C++11)
template<> class numeric_limits<float>;
template<> class numeric_limits<double>;
template<> class numeric_limits<long double>;

También se proporcionan especializaciones para todos los tipos de clase entero.

(desde C++20)

Además, existe una especialización para cada versión calificada-cv, de cada tipo no calificado-cv para el que la especialización existe, idéntica a la especialización no calificada, p. ej., se proporcionan std::numeric_limits<const int>, std::numeric_limits<volatile int>, y std::numeric_limits<const volatile int> y son equivalentes a std::numeric_limits<int>.

Los tipos de la biblioteca estándar (como std::size_t o std::streamsize) también pueden examinarse con los rasgos de tipo std::numeric_limits.

Los tipos estándar no aritméticos, como std::complex<T> o std::nullptr_t, no tienen especializaciones.

Las implementaciones pueden proporcionar especializaciones de std::numeric_limits para tipos específicos de la implementación: p.ej., GCC proporciona std::numeric_limits<__int128>. Las bibliotecas no estándar pueden añadir especializaciones para tipos proporcionados por la biblioteca, p.ej., OpenEXR proporciona std::numeric_limits<half> para un tipo de 16 bits de punto flotante.

Contenido

[editar] Parámetros de plantilla

T - Un tipo para el cual recuperar propiedades numéricas.

[editar] Constantes miembro

[estático]
identifica los tipos de std::numeric_limits que está especializada
Original:
identifies types for which std::numeric_limits is specialized
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica los tipos firmados
Original:
identifies signed types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica los tipos enteros
Original:
identifies integer types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica los tipos exactos
Original:
identifies exact types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica tipos de punto flotante que puede representar el valor especial "infinito positivo"
Original:
identifies floating-point types that can represent the special value "positive infinity"
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica tipos de punto flotante que puede representar el valor especial "tranquilo, no un número" (NaN)
Original:
identifies floating-point types that can represent the special value "quiet not-a-number" (NaN)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
identifica tipos de punto flotante que puede representar el valor especial "señalización no un número" (NaN)
Original:
identifies floating-point types that can represent the special value "signaling not-a-number" (NaN)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica el estilo desnormalización utilizado por el tipo de punto flotante
Original:
identifies the denormalization style used by the floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifies the floating-point types that detect loss of precision as denormalization loss rather than inexact result
(constante miembro pública estática) [editar]
[estático]
identifica el estilo de redondeo utilizado por el tipo
Original:
identifies the rounding style used by the type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica los IEC 559/IEEE 754 tipos de punto flotante
Original:
identifies the IEC 559/IEEE 754 floating-point types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifies types that represent a finite set of values
(constante miembro pública estática) [editar]
[estático]
identifica los tipos que manejan se desborda con la aritmética módulo
Original:
identifies types that handle overflows with modulo arithmetic
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
número de dígitos radix que pueden ser representadas sin cambio
Original:
number of radix digits that can be represented without change
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
número de dígitos decimales que pueden ser representadas sin cambio
Original:
number of decimal digits that can be represented without change
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático] (C++11)
número de dígitos decimales necesarias para diferenciar todos los valores de este tipo
Original:
number of decimal digits necessary to differentiate all values of this type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
la raíz o base entero utilizado por la representación del tipo dado
Original:
the radix or integer base used by the representation of the given type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
más que la menor potencia negativa de la base de que es un válido punto flotante normalizado valor uno
Original:
one more than the smallest negative power of the radix that is a valid normalized floating-point value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
la menor potencia negativa de diez que es válida normalizada valor de punto flotante
Original:
the smallest negative power of ten that is a valid normalized floating-point value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
mayor que la máxima potencia entera de la base de que es válida finito valor de punto flotante uno
Original:
one more than the largest integer power of the radix that is a valid finite floating-point value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
la mayor potencia entera de 10, que es válida finito valor de punto flotante
Original:
the largest integer power of 10 that is a valid finite floating-point value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica los tipos que pueden causar operaciones aritméticas para atraparlos
Original:
identifies types which can cause arithmetic operations to trap
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]
[estático]
identifica tipos de punto flotante que detectan tinyness antes de redondeo
Original:
identifies floating-point types that detect tinyness before rounding
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(constante miembro pública estática) [editar]

[editar] Funciones miembro

[estático]
devuelve el menor valor finito del tipo dado
Original:
returns the smallest finite value of the given type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático] (C++11)
Devuelve el menor valor finito del tipo dado
Original:
returns the lowest finite value of the given type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve el mayor valor finito del tipo dado
Original:
returns the largest finite value of the given type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve la diferencia entre 1.0 y el siguiente valor representable de lo dado tipo de punto flotante
Original:
returns the difference between 1.0 and the next representable value of the given floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve el error de redondeo máximo de lo dado tipo de punto flotante
Original:
returns the maximum rounding error of the given floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve el valor infinito positivo de lo dado tipo de punto flotante
Original:
returns the positive infinity value of the given floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve un valor NaN tranquilo de lo dado tipo de punto flotante
Original:
returns a quiet NaN value of the given floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve un valor NaN de señalización de lo dado tipo de punto flotante
Original:
returns a signaling NaN value of the given floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]
[estático]
devuelve el menor valor positivo subnormal de lo dado tipo de punto flotante
Original:
returns the smallest positive subnormal value of the given floating-point type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro estática pública) [editar]

[editar] Clases auxiliares

Indica modalidades de redondeo de punto flotante.
(enum) [editar]
Indica las modalidades de desnormalización de punto flotante.
(enum) [editar]

[editar] Relación con las constantes de macro de la biblioteca de C

Especialización Miembros
min() lowest()
(C++11)
max() epsilon() digits digits10 min_exponent min_exponent10 max_exponent max_exponent10 radix
numeric_limits< bool > 2
numeric_limits< char > CHAR_MIN CHAR_MIN CHAR_MAX 2
numeric_limits< signed char > SCHAR_MIN SCHAR_MIN SCHAR_MAX 2
numeric_limits< unsigned char > 0 0 UCHAR_MAX 2
numeric_limits< wchar_t > WCHAR_MIN WCHAR_MIN WCHAR_MAX 2
numeric_limits< char8_t > 0 0 UCHAR_MAX 2
numeric_limits< char16_t > 0 0 UINT_LEAST16_MAX 2
numeric_limits< char32_t > 0 0 UINT_LEAST32_MAX 2
numeric_limits< short > SHRT_MIN SHRT_MIN SHRT_MAX 2
numeric_limits< signed short >
numeric_limits< unsigned short > 0 0 USHRT_MAX 2
numeric_limits< int > INT_MIN INT_MIN INT_MAX 2
numeric_limits< signed int >
numeric_limits< unsigned int > 0 0 UINT_MAX 2
numeric_limits< long > LONG_MIN LONG_MIN LONG_MAX 2
numeric_limits< signed long >
numeric_limits< unsigned long > 0 0 ULONG_MAX 2
numeric_limits< long long > LLONG_MIN LLONG_MIN LLONG_MAX 2
numeric_limits< signed long long >
numeric_limits< unsigned long long > 0 0 ULLONG_MAX 2
numeric_limits< float > FLT_MIN -FLT_MAX FLT_MAX FLT_EPSILON FLT_MANT_DIG FLT_DIG FLT_MIN_EXP FLT_MIN_10_EXP FLT_MAX_EXP FLT_MAX_10_EXP FLT_RADIX
numeric_limits< double > DBL_MIN -DBL_MAX DBL_MAX DBL_EPSILON DBL_MANT_DIG DBL_DIG DBL_MIN_EXP DBL_MIN_10_EXP DBL_MAX_EXP DBL_MAX_10_EXP FLT_RADIX
numeric_limits< long double > LDBL_MIN -LDBL_MAX LDBL_MAX LDBL_EPSILON LDBL_MANT_DIG LDBL_DIG LDBL_MIN_EXP LDBL_MIN_10_EXP LDBL_MAX_EXP LDBL_MAX_10_EXP FLT_RADIX

[editar] Ejemplo

#include <limits>
#include <iostream>
 
int main() 
{
    std::cout << "type\tlowest()\tmin()\t\tmax()\n\n"
              << "bool\t"
              << std::numeric_limits<bool>::lowest() << "\t\t"
              << std::numeric_limits<bool>::min() << "\t\t"
              << std::numeric_limits<bool>::max() << '\n'
              << "uchar\t"
              << +std::numeric_limits<unsigned char>::lowest() << "\t\t"
              << +std::numeric_limits<unsigned char>::min() << "\t\t"
              << +std::numeric_limits<unsigned char>::max() << '\n'
              << "int\t"
              << std::numeric_limits<int>::lowest() << '\t'
              << std::numeric_limits<int>::min() << '\t'
              << std::numeric_limits<int>::max() << '\n'
              << "float\t"
              << std::numeric_limits<float>::lowest() << '\t'
              << std::numeric_limits<float>::min() << '\t'
              << std::numeric_limits<float>::max() << '\n'
              << "double\t"
              << std::numeric_limits<double>::lowest() << '\t'
              << std::numeric_limits<double>::min() << '\t'
              << std::numeric_limits<double>::max() << '\n';
}

Posible salida:

type	lowest()	min()		max()
 
bool	0		0		1
uchar	0		0		255
int	-2147483648	-2147483648	2147483647
float	-3.40282e+38	1.17549e-38	3.40282e+38
double	-1.79769e+308	2.22507e-308	1.79769e+308

[editar] Véase también