Top of document
©Copyright 1999 Rogue Wave Software

numeric_limits


     Numeric Limits Library

Summary

A class for representing information about scalar types.

Contents

Specializations

numeric_limits<float>
numeric_limits<double>
numeric_limits<long double>
numeric_limits<short>
numeric_limits<unsigned short>
numeric_limits<int>
numeric_limits<unsigned int>
numeric_limits<long>
numeric_limits<unsigned long>
numeric_limits<char>
numeric_limits<wchar_t>
numeric_limits<unsigned char>
numeric_limits<signed char>
numeric_limits<bool>

Synopsis

#include <limits>

template <class T>
class numeric_limits ;

Description

numeric_limits is a class for representing information about scalar types. Specializations are provided for each fundamental type, both floating point and integer, including bool.

This class encapsulates information that is contained in the <climits> and <cfloat> headers, as well as providing additional information that is not contained in any existing C or C++ header.

Not all of the information provided by members is meaningful for all specializations of numeric_limits. Any value which is not meaningful for a particular type is set to 0 or false.

Interface

template <class T>
 class numeric_limits {

 public:
 // General -- meaningful for all specializations.
    static const bool is_specialized ;
    static T min ();
    static T max ();
    static const int radix ;
    static const int digits ;
    static const int digits10 ;
    static const bool is_signed ;
    static const bool is_integer ;
    static const bool is_exact ;
    static const bool traps ;
    static const bool is_modulo ;
    static const bool is_bounded ;
 // Floating point specific.
    static T epsilon ();
    static T round_error ();
    static const int min_exponent10 ;
    static const int max_exponent10 ;
    static const int min_exponent ;
    static const int max_exponent ;
    static const bool has_infinity ;
    static const bool has_quiet_NaN ;
    static const bool has_signaling_NaN ;
    static const bool is_iec559 ;
    static const bool has_denorm ;
    static const bool tinyness_before ;
    static const float_round_style round_style ;
    static T denorm_min ();
    static T infinity ();
    static T quiet_NaN ();
    static T signaling_NaN ();
 };
 enum float_round_style {
   round_indeterminate       = -1,
   round_toward_zero         =  0,
   round_to_nearest          =  1,
   round_toward_infinity     =  2,
   round_toward_neg_infinity =  3
 };

Member fields and functions

static T 
denorm_min ();
static const int 
digits ;
static const int 
digits10 ;
static T 
epsilon ();
static const bool 
has_denorm ;
static const bool 
has_infinity ;
static const bool 
has_quiet_NaN ;
static const bool 
has_signaling_NaN ;
static T 
infinity ();
static const bool 
is_bounded ;
static const bool 
is_exact ;
static const bool 
is_iec559 ;
static const bool 
is_integer ;
static const bool 
is_modulo ;
static const bool 
is_signed ;
static const bool 
is_specialized ;
static T
max ();
static const int 
max_exponent ;
static const int 
max_exponent10 ;
static T 
min ();
static const int 
min_exponent ;
static const int 
min_exponent10 ;
static T 
quiet_NaN ();
static const int 
radix ;
static T 
round_error ();
static const float_round_style 
round_style ;
static T 
signaling_NaN();
static const bool 
tinyness_before ;
static const bool 
traps ;

Example

//
// limits.cpp
//
 #include <limits>
 int main() 
 {
    numeric_limits<float> float_info;
    if (float_info.is_specialized && float_info.has_infinity)
    {
      // get value of infinity 
      float finfinity=float_info.infinity(); 
    }
    return 0;
 }

Warning

The specializations for wide chars and bool will only be available if your compiler has implemented them as real types and not simulated them with typedefs.

See Also

IEEE Standard for Binary Floating-Point Arithmetic, 345 East 47th Street, New York, NY 10017

Language Independent Arithmetic (LIA-1)


Top of document