## numeric_limits

    Numeric Limits Library

- Summary
- Data Type and Member Function Indexes
- Specializations
- Synopsis
- Description
- Interface
- Member Fields and Functions
- Example
- Warnings
- See Also

### Summary

A class for representing information about scalar types.

### Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Data Types
digits digits10 has_denorm has_infinity has_quiet_NaN has_signaling_NaN | is_bounded is_exact is_iec559 is_integer is_modulo is_signed | is_specialized max_exponent max_exponent10 min_exponent min_exponent10 radix | round_style tinyness_before traps

Member Functions
denorm_min() epsilon() infinity() max() min() quiet_NaN() | round_error() signaling_NaN()

### 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 included for each fundamental type, both floating point and integer, including `bool`.

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

Not all of the information given by members is meaningful for all specializations of numeric_limits. Any value that 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 () throw();
        static T max () throw();
        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 () throw();
        static T round_error () throw();
        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 float_denorm_style has_denorm ;
        static const bool has_denorm_loss;
        static const bool tinyness_before ;
        static const float_round_style round_style ;
        static T denorm_min () throw();
        static T infinity () throw();
        static T quiet_NaN () throw();
        static T signaling_NaN () throw();
     };

     enum float_round_style {
       round_indeterminate       = -1,
       round_toward_zero         =  0,
       round_to_nearest          =  1,
       round_toward_infinity     =  2,
       round_toward_neg_infinity =  3
     };
     enum float_denorm_style {
       denorm_indeterminate      = -1,
       denorm_absent             =  0,
       denorm_present            =  1
     };

### Member Fields and Functions

    static T
    denorm_min () throw();

Returns the minimum denormalized value. Meaningful for all floating point types. For types that do not allow denormalized values, this method must return the minimum normalized value.

    static const int
    digits ;

The number of radix digits that can be represented without change. For built-in integer types, `digits` is usually the number of non-sign bits in the representation. For floating point types, `digits` is the number of radix digits in the mantissa. This member is meaningful for all specializations that declare `is_bounded` to be `true`.

    static const int
    digits10 ;

The number of base 10 digits that can be represented without change. This function is meaningful for all specializations that declare `is_bounded` to be `true`.

    static T
    epsilon () throw();

Returns the machine epsilon (the difference between `1` and the least value greater than `1` that is representable). This function is meaningful for floating point types only.

    static const float_denorm_style
    has_denorm ;

Returns `denorm_present` if the type allows denormalized values. Returns `denorm_absent` if the type does not allow denormalized values. Returns `denorm_indeterminate` if it is indeterminate at compile time whether the type allows denormalized values. It is meaningful for floating point types only.

    static const bool
    has_infinity ;

This field is `true` if the type has a representation for positive infinity. It is meaningful for floating point types only. This field must be `true` for any type claiming conformance to IEC 559.

    static const bool
    has_quiet_NaN ;

This field is `true` if the type has a representation for a quiet (non-signaling) "Not a Number". It is meaningful for floating point types only and must be `true` for any type claiming conformance to IEC 559.

    static const bool
    has_signaling_NaN ;

This field is `true` if the type has a representation for a signaling "Not a Number". It is meaningful for floating point types only, and must be `true` for any type claiming conformance to IEC 559.

    static T
    infinity () throw();

Returns the representation of positive infinity, if available. This member function is meaningful for only those specializations that declare `has_infinity` to be `true`. Required for any type claiming conformance to IEC 559.

    static const bool
    is_bounded ;

This field is `true` if the set of values representable by the type is finite. All built-in C types are bounded; this member would be `false` for arbitrary precision types.

    static const bool
    is_exact ;

This static member field is `true` if the type uses an exact representation. All integer types are exact, but not vice versa. For example, rational and fixed-exponent representations are exact but not integer. This member is meaningful for all specializations.

    static const bool
    is_iec559 ;

This member is `true` if and only if the type adheres to the IEC 559 standard. It is meaningful for floating point types only.

    static const bool
    is_integer ;

This member is `true` if the type is integer. This member is meaningful for all specializations.

    static const bool
    is_modulo ;

This field is `true` if the type is modulo. Generally, this is `false` for floating types, `true` for unsigned integers, and `true` for signed integers on most machines. A type is modulo if it is possible to add two positive numbers and have a result that wraps around to a third number, which is less.

    static const bool
    is_signed ;

This member is `true` if the type is signed. This member is meaningful for all specializations.

    static const bool
    is_specialized ;

Indicates whether numeric_limits has been specialized for type `T`. This flag must be `true` for all specializations of `numeric_limits`. For the default numeric_limits<T> template, this flag must be `false`.

    static T
    max () throw();

Returns the maximum finite value. This function is meaningful for all specializations that declare `is_bounded` to be `true`.

    static const int
    max_exponent ;

The maximum positive integer such that the radix raised to the power one less than that integer is in range. This field is meaningful for floating point types only.

    static const int
    max_exponent10 ;

The maximum positive integer such that 10 raised to that power is in range. This field is meaningful for floating point types only.

    static T
    min () throw();

Returns the minimum finite value. For floating point types with denormalization, `min()`must return the minimum normalized value. The minimum denormalized value is given by `denorm_min()`. This function is meaningful for all specializations that declare `is_bounded` to be `true`, or `is_bounded == false && is_signed == false`.

    static const int
    min_exponent ;

The minimum negative integer such that the radix raised to the power one less than that integer is in range. This field is meaningful for floating point types only.

    static const int
    min_exponent10 ;

The minimum negative integer such that 10 raised to that power is in range. This field is meaningful for floating point types only.

    static T
    quiet_NaN () throw();

Returns the representation of a quiet "Not a Number", if available. This function is meaningful only for those specializations that declare `has_quiet_NaN` to be `true`. This field is required for any type claiming conformance to IEC 559.

    static const int
    radix ;

For floating types, specifies the base or radix of the exponent representation (often 2). For integer types, this member must specify the base of the representation. This field is meaningful for all specializations.

    static T
    round_error () throw();

Returns the measure of the maximum rounding error. This function is meaningful for floating point types only.

    static const float_round_style
    round_style ;

The rounding style for the type. Specializations for integer types must return `round_toward_zero`. This is meaningful for all floating point types.

    static T
    signaling_NaN() throw();

Returns the representation of a signaling "Not a Number", if available. This function is meaningful for only those specializations that declare `has_signaling_NaN` to be `true`. This function must be meaningful for any type claiming conformance to IEC 559.

    static const bool
    tinyness_before ;

This member is `true` if `tinyness` is detected before rounding. It is meaningful for floating point types only.

    static const bool
    traps ;

This field is `true` if trapping is implemented for this type. The `traps` field is meaningful for all specializations.

### Example

    //
    // limits.cpp
    //
     #include <limits>
     #include <iostream>
     using namespace std;

     int main()
     {
        numeric_limits<float> float_info;
        if (float_info.is_specialized &&
            float_info.has_infinity)
        {
          // get value of infinity
          cout<< float_info.infinity() << endl;
        }
        return 0;
     }

### Warnings

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

If your compiler does not support namespaces, then you do not need the using declaration for `std`.

### See Also

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

Language Independent Arithmetic (LIA-1)

Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998