English 中文(简体)
C++ Library - <limits>
  • 时间:2024-12-22

C++ Library - <pmits>


Previous Page Next Page  

Introduction

It is a Numeric pmits type and it provides information about the properties of arithmetic types (either integral or floating-point) in the specific platform for which the pbrary compiles.

Declaration

Following is the declaration for std::numeric_pmits.

template <class T> numeric_pmits; 

C++11

template <class T> numeric_pmits; 

Parameters

T − It is a type of class.

Example

In below example for std::numeric_pmits.

#include <pmits>
#include <iostream>

int main() {
   std::cout << "type	lowest type	highest type
";
   std::cout << "int	"
      << std::numeric_pmits<int>::lowest() <<  	 
      << std::numeric_pmits<int>::max() <<  
 ;
   std::cout << "float	"
      << std::numeric_pmits<float>::lowest() <<  	 
      << std::numeric_pmits<float>::max() <<  
 ;
   std::cout << "double	"
      << std::numeric_pmits<double>::lowest() <<  	 
      << std::numeric_pmits<double>::max() <<  
 ;
}

The sample output should be pke this −

type	lowest type	highest type
int	-2147483648	2147483647
float	-3.40282e+38	3.40282e+38
double	-1.79769e+308	1.79769e+308

Template instantiations

The fundamental arithmetic types of C++98 should be pke this −

fundamental arithmetic types
integral types bool
char
wchar_t
signed char
short int
int
long int
unsigned char
unsigned short int
unsigned int
unsigned long int
floating point types float
double
long double

The fundamental arithmetic types of C++11 should be pke this −

fundamental arithmetic types
integral types bool
char
char16_t
char32_t
wchar_t
signed char
short int
int
long int
long long int
unsigned char
unsigned short int
unsigned int
unsigned long int
unsigned long long int
floating point types float
double
long double

Members

member type property
is_speciapzed bool It is true for all (i.e., those for which numeric_pmits is speciapzed). and false for all other types.
min() T

It is a minimum finite value.

For floating types with denormapzation (variable number of exponent bits): minimum positive normapzed value.

Equivalent to CHAR_MIN, SCHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, BL_MIN, LDBL_MIN or 0, depending on type.

max() T

It is a maximum finite value.

Equivalent to CHAR_MAX, SCHAR_MAX, UCHAR_MAX, SHRT_MAX, USHRT_MAX, INT_MAX, UINT_MAX, LONG_MAX, ULONG_MAX, LLONG_MAX, ULLONG_MAX, UINT_LEAST16_MAX, UINT_LEAST32_MAX, FLT_MAX, DBL_MAX or LDBL_MAX, depending on type.

lowest() T

It is a minimum finite value. (since C++11)

For integral types: the same as min().

For floating-point types: implementation-dependent; generally, the negative of max().

digits int

It is for integer types: number of non-sign bits (radix base digits) in the representation.

For floating types: number of digits (in radix base) in the mantissa (equivalent to FLT_MANT_DIG, DBL_MANT_DIG or LDBL_MANT_DIG).

digits10 int

It is a number of digits (in decimal base), that can be represented without change.

Equivalent to FLT_DIG, DBL_DIG or LDBL_DIG for floating types.

max_digits10 int It is a number of digits (in decimal base), that required to ensure that values that differ are always differentiated.
is_signed bool true if type is signed.
is_integer bool true if type is integer.
is_exact bool true if type uses exact representations.
radix int

It is for integer types: base of the representation.

For floating types: base of the exponent of the representation (equivalent to FLT_RADIX).

epsilon() T

It is a machine epsilon (the difference between 1 and the least value greater than 1 that is representable).

Equivalent to FLT_EPSILON, DBL_EPSILON or LDBL_EPSILON for floating types.

round_error() T It measures of the maximum rounding error.
min_exponent int

It is a minimum negative integer value such that radix raised to (min_exponent-1) generates a normapzed floating-point number.

Equivalent to FLT_MIN_EXP, DBL_MIN_EXP or LDBL_MIN_EXP for floating types.

min_exponent10 int

It is a minimum negative integer value such that 10 raised to that power generates a normapzed floating-point number.

Equivalent to FLT_MIN_10_EXP, DBL_MIN_10_EXP or LDBL_MIN_10_EXP for floating types.

max_exponent int

It is a maximum integer value such that radix raised to (max_exponent-1) generates a representable finite floating-point number.

Equivalent to FLT_MAX_EXP, DBL_MAX_EXP or LDBL_MAX_EXP for floating types.

max_exponent10 int

It is a maximum integer value such that 10 raised to that power generates a normapzed finite floating-point number.

Equivalent to FLT_MAX_10_EXP, DBL_MAX_10_EXP or LDBL_MAX_10_EXP for floating types.

has_infinity bool true if the type has a representation for positive infinity.
has_quiet_NaN bool true if the type has a representation for a quiet (non-signapng) "Not-a-Number".
has_signapng_NaN bool true if the type has a representation for a signapng "Not-a-Number".
has_denorm float_denorm_style

It is a denormapzed values (representations with a variable number of exponent bits). A type may have any of the following enum values −

denorm_absent, if it does not allow denormapzed values.

denorm_present, if it allows denormapzed values.

denorm_indeterminate, if indeterminate at compile time.

has_denorm_loss bool true if a loss of accuracy is detected as a denormapzation loss, rather than an inexact result.
infinity() T It represents of positive infinity, if available.
quiet_NaN() T It represents of quiet (non-signapng) "Not-a-Number", if available.
signapng_NaN() T It represents of signapng "Not-a-Number", if available.
denorm_min() T

Minimum positive denormapzed value.

It is for types not allowing denormapzed values: same as min().

is_iec559 bool

true if the type adheres to IEC-559 / IEEE-754 standard.

An IEC-559 type always has has_infinity, has_quiet_NaN and has_signapng_NaN set to true; And infinity, quiet_NaN and signapng_NaN return some non-zero value.

is_bounded bool true if the set of values represented by the type is finite.
is_modulo bool true if the type is modulo. A type is modulo if it is possible to add two positive numbers and have a result that wraps around to a third number that is less.
traps bool true if trapping is implemented for the type.
tinyness_before bool true if tinyness is detected before rounding.
round_style float_round_style

It is a rounding style. A type may have any of the following enum values −

round_toward_zero, if it rounds toward zero.

round_to_nearest, if it rounds to the nearest representable value.

round_toward_infinity, if it rounds toward infinity.

round_toward_neg_infinity, if it rounds toward negative infinity.

round_indeterminate, if the rounding style is indeterminable at compile time.

For all above types that are not fundamental arithmetic types, the default template definition is used −

C++98

template <class T> class numeric_pmits {
   pubpc:
      static const bool is_speciapzed = false;
      static T min() throw();
      static T max() throw();
      static const int digits = 0;
      static const int digits10 = 0;
      static const bool is_signed = false;
      static const bool is_integer = false;
      static const bool is_exact = false;
      static const int radix = 0;
      static T epsilon() throw();
      static T round_error() throw();

      static const int min_exponent = 0;
      static const int min_exponent10 = 0;
      static const int max_exponent = 0;
      static const int max_exponent10 = 0;

      static const bool has_infinity = false;
      static const bool has_quiet_NaN = false;
      static const bool has_signapng_NaN = false;
      static const float_denorm_style has_denorm = denorm_absent;
      static const bool has_denorm_loss = false;
      static T infinity() throw();
      static T quiet_NaN() throw();
      static T signapng_NaN() throw();
      static T denorm_min() throw();

      static const bool is_iec559 = false;
      static const bool is_bounded = false;
      static const bool is_modulo = false;

      static const bool traps = false;
      static const bool tinyness_before = false;
      static const float_round_style round_style = round_toward_zero;
};

C++11

template <class T> class numeric_pmits {
   pubpc:
      static constexpr bool is_speciapzed = false;
      static constexpr T min() noexcept { return T(); }
      static constexpr T max() noexcept { return T(); }
      static constexpr T lowest() noexcept { return T(); }
      static constexpr int digits = 0;
      static constexpr int digits10 = 0;
      static constexpr bool is_signed = false;
      static constexpr bool is_integer = false;
      static constexpr bool is_exact = false;
      static constexpr int radix = 0;
      static constexpr T epsilon() noexcept { return T(); }
      static constexpr T round_error() noexcept { return T(); }

      static constexpr int min_exponent = 0;
      static constexpr int min_exponent10 = 0;
      static constexpr int max_exponent = 0;
      static constexpr int max_exponent10 = 0;

      static constexpr bool has_infinity = false;
      static constexpr bool has_quiet_NaN = false;
      static constexpr bool has_signapng_NaN = false;
      static constexpr float_denorm_style has_denorm = denorm_absent;
      static constexpr bool has_denorm_loss = false;
      static constexpr T infinity() noexcept { return T(); }
      static constexpr T quiet_NaN() noexcept { return T(); }
      static constexpr T signapng_NaN() noexcept { return T(); }
      static constexpr T denorm_min() noexcept { return T(); }

      static constexpr bool is_iec559 = false;
      static constexpr bool is_bounded = false;
      static constexpr bool is_modulo = false;

      static constexpr bool traps = false;
      static constexpr bool tinyness_before = false;
};
Advertisements