# limits

Go to the documentation of this file.

    00001 // The template and inlines for the -*- C++ -*- numeric_limits classes.
    00002
    00003 // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 // Note: this is not a conforming implementation.
    00031 // Written by Gabriel Dos Reis <gdr@codesourcery.com>
    00032
    00033 //
    00034 // ISO 14882:1998
    00035 // 18.2.1
    00036 //
    00037
    00038 /** @file limits
    00039  *  This is a Standard C++ Library header.  You should @c #include this header
    00040  *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
    00041  */
    00042
    00043 #ifndef _GLIBCXX_NUMERIC_LIMITS
    00044 #define _GLIBCXX_NUMERIC_LIMITS 1
    00045
    00046 #pragma GCC system_header
    00047
    00048 #include <bits/c++config.h>
    00049
    00050 //
    00051 // The numeric_limits<> traits document implementation-defined aspects
    00052 // of fundamental arithmetic data types (integers and floating points).
    00053 // From Standard C++ point of view, there are 13 such types:
    00054 //   * integers
    00055 //         bool                             (1)
    00056 //         char, signed char, unsigned char         (3)
    00057 //         short, unsigned short                (2)
    00058 //         int, unsigned                    (2)
    00059 //         long, unsigned long                  (2)
    00060 //
    00061 //   * floating points
    00062 //         float                        (1)
    00063 //         double                       (1)
    00064 //         long double                      (1)
    00065 //
    00066 // GNU C++ undertstands (where supported by the host C-library)
    00067 //   * integer
    00068 //         long long, unsigned long long            (2)
    00069 //
    00070 // which brings us to 15 fundamental arithmetic data types in GNU C++.
    00071 //
    00072 //
    00073 // Since a numeric_limits<> is a bit tricky to get right, we rely on
    00074 // an interface composed of macros which should be defined in config/os
    00075 // or config/cpu when they differ from the generic (read arbitrary)
    00076 // definitions given here.
    00077 //
    00078
    00079 // These values can be overridden in the target configuration file.
    00080 // The default values are appropriate for many 32-bit targets.
    00081
    00082 // GCC only intrinsicly supports modulo integral types.  The only remaining
    00083 // integral exceptional values is division by zero.  Only targets that do not
    00084 // signal division by zero in some "hard to ignore" way should use false.
    00085 #ifndef __glibcxx_integral_traps
    00086 # define __glibcxx_integral_traps true
    00087 #endif
    00088
    00089 // float
    00090 //
    00091
    00092 // Default values.  Should be overriden in configuration files if necessary.
    00093
    00094 #ifndef __glibcxx_float_has_denorm_loss
    00095 #  define __glibcxx_float_has_denorm_loss false
    00096 #endif
    00097 #ifndef __glibcxx_float_traps
    00098 #  define __glibcxx_float_traps false
    00099 #endif
    00100 #ifndef __glibcxx_float_tinyness_before
    00101 #  define __glibcxx_float_tinyness_before false
    00102 #endif
    00103
    00104 // double
    00105
    00106 // Default values.  Should be overriden in configuration files if necessary.
    00107
    00108 #ifndef __glibcxx_double_has_denorm_loss
    00109 #  define __glibcxx_double_has_denorm_loss false
    00110 #endif
    00111 #ifndef __glibcxx_double_traps
    00112 #  define __glibcxx_double_traps false
    00113 #endif
    00114 #ifndef __glibcxx_double_tinyness_before
    00115 #  define __glibcxx_double_tinyness_before false
    00116 #endif
    00117
    00118 // long double
    00119
    00120 // Default values.  Should be overriden in configuration files if necessary.
    00121
    00122 #ifndef __glibcxx_long_double_has_denorm_loss
    00123 #  define __glibcxx_long_double_has_denorm_loss false
    00124 #endif
    00125 #ifndef __glibcxx_long_double_traps
    00126 #  define __glibcxx_long_double_traps false
    00127 #endif
    00128 #ifndef __glibcxx_long_double_tinyness_before
    00129 #  define __glibcxx_long_double_tinyness_before false
    00130 #endif
    00131
    00132 // You should not need to define any macros below this point.
    00133
    00134 #define __glibcxx_signed(T) ((T)(-1) < 0)
    00135
    00136 #define __glibcxx_min(T) \
    00137   (__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0)
    00138
    00139 #define __glibcxx_max(T) \
    00140   (__glibcxx_signed (T) ? ((T)1 << __glibcxx_digits (T)) - 1 : ~(T)0)
    00141
    00142 #define __glibcxx_digits(T) \
    00143   (sizeof(T) * __CHAR_BIT__ - __glibcxx_signed (T))
    00144
    00145 // The fraction 643/2136 approximates log10(2) to 7 significant digits.
    00146 #define __glibcxx_digits10(T) \
    00147   (__glibcxx_digits (T) * 643 / 2136)
    00148
    00149
    00150 namespace std
    00151 {
    00152   /**
    00153    *  @brief Describes the rounding style for floating-point types.
    00154    *
    00155    *  This is used in the std::numeric_limits class.
    00156   */
    00157   enum float_round_style
    00158   {
    00159     round_indeterminate       = -1,    ///< Self-explanatory.
    00160     round_toward_zero         = 0,     ///< Self-explanatory.
    00161     round_to_nearest          = 1,     ///< To the nearest representable value.
    00162     round_toward_infinity     = 2,     ///< Self-explanatory.
    00163     round_toward_neg_infinity = 3      ///< Self-explanatory.
    00164   };
    00165
    00166   /**
    00167    *  @brief Describes the denormalization for floating-point types.
    00168    *
    00169    *  These values represent the presence or absence of a variable number
    00170    *  of exponent bits.  This type is used in the std::numeric_limits class.
    00171   */
    00172   enum float_denorm_style
    00173   {
    00174     /// Indeterminate at compile time whether denormalized values are allowed.
    00175     denorm_indeterminate = -1,
    00176     /// The type does not allow denormalized values.
    00177     denorm_absent        = 0,
    00178     /// The type allows denormalized values.
    00179     denorm_present       = 1
    00180   };
    00181
    00182   /**
    00183    *  @brief Part of std::numeric_limits.
    00184    *
    00185    *  The @c static @c const members are usable as integral constant
    00186    *  expressions.
    00187    *
    00188    *  @note This is a seperate class for purposes of efficiency; you
    00189    *        should only access these members as part of an instantiation
    00190    *        of the std::numeric_limits class.
    00191   */
    00192   struct __numeric_limits_base
    00193   {
    00194     /** This will be true for all fundamental types (which have
    00195         specializations), and false for everything else.  */
    00196     static const bool is_specialized = false;
    00197
    00198     /** The number of @c radix digits that be represented without change:  for
    00199         integer types, the number of non-sign bits in the mantissa; for
    00200         floating types, the number of @c radix digits in the mantissa.  */
    00201     static const int digits = 0;
    00202     /** The number of base 10 digits that can be represented without change. */
    00203     static const int digits10 = 0;
    00204     /** True if the type is signed.  */
    00205     static const bool is_signed = false;
    00206     /** True if the type is integer.
    00207      *  @if maint
    00208      *  Is this supposed to be "if the type is integral"?
    00209      *  @endif
    00210     */
    00211     static const bool is_integer = false;
    00212     /** True if the type uses an exact representation.  "All integer types are
    00213         exact, but not all exact types are integer.  For example, rational and
    00214         fixed-exponent representations are exact but not integer."
    00215         [18.2.1.2]/15  */
    00216     static const bool is_exact = false;
    00217     /** For integer types, specifies the base of the representation.  For
    00218         floating types, specifies the base of the exponent representation.  */
    00219     static const int radix = 0;
    00220
    00221     /** The minimum negative integer such that @c radix raised to the power of
    00222         (one less than that integer) is a normalized floating point number.  */
    00223     static const int min_exponent = 0;
    00224     /** The minimum negative integer such that 10 raised to that power is in
    00225         the range of normalized floating point numbers.  */
    00226     static const int min_exponent10 = 0;
    00227     /** The maximum positive integer such that @c radix raised to the power of
    00228         (one less than that integer) is a representable finite floating point
    00229     number.  */
    00230     static const int max_exponent = 0;
    00231     /** The maximum positive integer such that 10 raised to that power is in
    00232         the range of representable finite floating point numbers.  */
    00233     static const int max_exponent10 = 0;
    00234
    00235     /** True if the type has a representation for positive infinity.  */
    00236     static const bool has_infinity = false;
    00237     /** True if the type has a representation for a quiet (non-signaling)
    00238         "Not a Number."  */
    00239     static const bool has_quiet_NaN = false;
    00240     /** True if the type has a representation for a signaling
    00241         "Not a Number."  */
    00242     static const bool has_signaling_NaN = false;
    00243     /** See std::float_denorm_style for more information.  */
    00244     static const float_denorm_style has_denorm = denorm_absent;
    00245     /** "True if loss of accuracy is detected as a denormalization loss,
    00246         rather than as an inexact result." [18.2.1.2]/42  */
    00247     static const bool has_denorm_loss = false;
    00248
    00249     /** True if-and-only-if the type adheres to the IEC 559 standard, also
    00250         known as IEEE 754.  (Only makes sense for floating point types.)  */
    00251     static const bool is_iec559 = false;
    00252     /** "True if the set of values representable by the type is finite.   All
    00253         built-in types are bounded, this member would be false for arbitrary
    00254     precision types." [18.2.1.2]/54  */
    00255     static const bool is_bounded = false;
    00256     /** True if the type is @e modulo, that is, if it is possible to add two
    00257         positive numbers and have a result that wraps around to a third number
    00258         that is less.  Typically false for floating types, true for unsigned
    00259         integers, and true for signed integers.  */
    00260     static const bool is_modulo = false;
    00261
    00262     /** True if trapping is implemented for this type.  */
    00263     static const bool traps = false;
    00264     /** True if tinyness is detected before rounding.  (see IEC 559)  */
    00265     static const bool tinyness_before = false;
    00266     /** See std::float_round_style for more information.  This is only
    00267         meaningful for floating types; integer types will all be
    00268     round_toward_zero.  */
    00269     static const float_round_style round_style = round_toward_zero;
    00270   };
    00271
    00272   /**
    00273    *  @brief Properties of fundamental types.
    00274    *
    00275    *  This class allows a program to obtain information about the
    00276    *  representation of a fundamental type on a given platform.  For
    00277    *  non-fundamental types, the functions will return 0 and the data
    00278    *  members will all be @c false.
    00279    *
    00280    *  @if maint
    00281    *  _GLIBCXX_RESOLVE_LIB_DEFECTS:  DRs 201 and 184 (hi Gaby!) are
    00282    *  noted, but not incorporated in this documented (yet).
    00283    *  @endif
    00284   */
    00285   template<typename _Tp>
    00286     struct numeric_limits : public __numeric_limits_base
    00287     {
    00288       /** The minimum finite value, or for floating types with
    00289           denormalization, the minimum positive normalized value.  */
    00290       static _Tp min() throw() { return static_cast<_Tp>(0); }
    00291       /** The maximum finite value.  */
    00292       static _Tp max() throw() { return static_cast<_Tp>(0); }
    00293       /** The @e machine @e epsilon:  the difference between 1 and the least
    00294           value greater than 1 that is representable.  */
    00295       static _Tp epsilon() throw() { return static_cast<_Tp>(0); }
    00296       /** The maximum rounding error measurement (see LIA-1).  */
    00297       static _Tp round_error() throw() { return static_cast<_Tp>(0); }
    00298       /** The representation of positive infinity, if @c has_infinity.  */
    00299       static _Tp infinity() throw()  { return static_cast<_Tp>(0); }
    00300       /** The representation of a quiet "Not a Number," if @c has_quiet_NaN. */
    00301       static _Tp quiet_NaN() throw() { return static_cast<_Tp>(0); }
    00302       /** The representation of a signaling "Not a Number," if
    00303           @c has_signaling_NaN. */
    00304       static _Tp signaling_NaN() throw() { return static_cast<_Tp>(0); }
    00305       /** The minimum positive denormalized value.  For types where
    00306           @c has_denorm is false, this is the minimum positive normalized
    00307       value.  */
    00308       static _Tp denorm_min() throw() { return static_cast<_Tp>(0); }
    00309     };
    00310
    00311   // Now there follow 15 explicit specializations.  Yes, 15.  Make sure
    00312   // you get the count right.
    00313   template<>
    00314     struct numeric_limits<bool>
    00315     {
    00316       static const bool is_specialized = true;
    00317
    00318       static bool min() throw()
    00319       { return false; }
    00320       static bool max() throw()
    00321       { return true; }
    00322
    00323       static const int digits = 1;
    00324       static const int digits10 = 0;
    00325       static const bool is_signed = false;
    00326       static const bool is_integer = true;
    00327       static const bool is_exact = true;
    00328       static const int radix = 2;
    00329       static bool epsilon() throw()
    00330       { return false; }
    00331       static bool round_error() throw()
    00332       { return false; }
    00333
    00334       static const int min_exponent = 0;
    00335       static const int min_exponent10 = 0;
    00336       static const int max_exponent = 0;
    00337       static const int max_exponent10 = 0;
    00338
    00339       static const bool has_infinity = false;
    00340       static const bool has_quiet_NaN = false;
    00341       static const bool has_signaling_NaN = false;
    00342       static const float_denorm_style has_denorm = denorm_absent;
    00343       static const bool has_denorm_loss = false;
    00344
    00345       static bool infinity() throw()
    00346       { return false; }
    00347       static bool quiet_NaN() throw()
    00348       { return false; }
    00349       static bool signaling_NaN() throw()
    00350       { return false; }
    00351       static bool denorm_min() throw()
    00352       { return false; }
    00353
    00354       static const bool is_iec559 = false;
    00355       static const bool is_bounded = true;
    00356       static const bool is_modulo = false;
    00357
    00358       // It is not clear what it means for a boolean type to trap.
    00359       // This is a DR on the LWG issue list.  Here, I use integer
    00360       // promotion semantics.
    00361       static const bool traps = __glibcxx_integral_traps;
    00362       static const bool tinyness_before = false;
    00363       static const float_round_style round_style = round_toward_zero;
    00364     };
    00365
    00366   template<>
    00367     struct numeric_limits<char>
    00368     {
    00369       static const bool is_specialized = true;
    00370
    00371       static char min() throw()
    00372       { return __glibcxx_min(char); }
    00373       static char max() throw()
    00374       { return __glibcxx_max(char); }
    00375
    00376       static const int digits = __glibcxx_digits (char);
    00377       static const int digits10 = __glibcxx_digits10 (char);
    00378       static const bool is_signed = __glibcxx_signed (char);
    00379       static const bool is_integer = true;
    00380       static const bool is_exact = true;
    00381       static const int radix = 2;
    00382       static char epsilon() throw()
    00383       { return 0; }
    00384       static char round_error() throw()
    00385       { return 0; }
    00386
    00387       static const int min_exponent = 0;
    00388       static const int min_exponent10 = 0;
    00389       static const int max_exponent = 0;
    00390       static const int max_exponent10 = 0;
    00391
    00392       static const bool has_infinity = false;
    00393       static const bool has_quiet_NaN = false;
    00394       static const bool has_signaling_NaN = false;
    00395       static const float_denorm_style has_denorm = denorm_absent;
    00396       static const bool has_denorm_loss = false;
    00397
    00398       static char infinity() throw()
    00399       { return char(); }
    00400       static char quiet_NaN() throw()
    00401       { return char(); }
    00402       static char signaling_NaN() throw()
    00403       { return char(); }
    00404       static char denorm_min() throw()
    00405       { return static_cast<char>(0); }
    00406
    00407       static const bool is_iec559 = false;
    00408       static const bool is_bounded = true;
    00409       static const bool is_modulo = true;
    00410
    00411       static const bool traps = __glibcxx_integral_traps;
    00412       static const bool tinyness_before = false;
    00413       static const float_round_style round_style = round_toward_zero;
    00414     };
    00415
    00416   template<>
    00417     struct numeric_limits<signed char>
    00418     {
    00419       static const bool is_specialized = true;
    00420
    00421       static signed char min() throw()
    00422       { return -__SCHAR_MAX__ - 1; }
    00423       static signed char max() throw()
    00424       { return __SCHAR_MAX__; }
    00425
    00426       static const int digits = __glibcxx_digits (signed char);
    00427       static const int digits10 = __glibcxx_digits10 (signed char);
    00428       static const bool is_signed = true;
    00429       static const bool is_integer = true;
    00430       static const bool is_exact = true;
    00431       static const int radix = 2;
    00432       static signed char epsilon() throw()
    00433       { return 0; }
    00434       static signed char round_error() throw()
    00435       { return 0; }
    00436
    00437       static const int min_exponent = 0;
    00438       static const int min_exponent10 = 0;
    00439       static const int max_exponent = 0;
    00440       static const int max_exponent10 = 0;
    00441
    00442       static const bool has_infinity = false;
    00443       static const bool has_quiet_NaN = false;
    00444       static const bool has_signaling_NaN = false;
    00445       static const float_denorm_style has_denorm = denorm_absent;
    00446       static const bool has_denorm_loss = false;
    00447
    00448       static signed char infinity() throw()
    00449       { return static_cast<signed char>(0); }
    00450       static signed char quiet_NaN() throw()
    00451       { return static_cast<signed char>(0); }
    00452       static signed char signaling_NaN() throw()
    00453       { return static_cast<signed char>(0); }
    00454       static signed char denorm_min() throw()
    00455       { return static_cast<signed char>(0); }
    00456
    00457       static const bool is_iec559 = false;
    00458       static const bool is_bounded = true;
    00459       static const bool is_modulo = true;
    00460
    00461       static const bool traps = __glibcxx_integral_traps;
    00462       static const bool tinyness_before = false;
    00463       static const float_round_style round_style = round_toward_zero;
    00464     };
    00465
    00466   template<>
    00467     struct numeric_limits<unsigned char>
    00468     {
    00469       static const bool is_specialized = true;
    00470
    00471       static unsigned char min() throw()
    00472       { return 0; }
    00473       static unsigned char max() throw()
    00474       { return __SCHAR_MAX__ * 2U + 1; }
    00475
    00476       static const int digits = __glibcxx_digits (unsigned char);
    00477       static const int digits10 = __glibcxx_digits10 (unsigned char);
    00478       static const bool is_signed = false;
    00479       static const bool is_integer = true;
    00480       static const bool is_exact = true;
    00481       static const int radix = 2;
    00482       static unsigned char epsilon() throw()
    00483       { return 0; }
    00484       static unsigned char round_error() throw()
    00485       { return 0; }
    00486
    00487       static const int min_exponent = 0;
    00488       static const int min_exponent10 = 0;
    00489       static const int max_exponent = 0;
    00490       static const int max_exponent10 = 0;
    00491
    00492       static const bool has_infinity = false;
    00493       static const bool has_quiet_NaN = false;
    00494       static const bool has_signaling_NaN = false;
    00495       static const float_denorm_style has_denorm = denorm_absent;
    00496       static const bool has_denorm_loss = false;
    00497
    00498       static unsigned char infinity() throw()
    00499       { return static_cast<unsigned char>(0); }
    00500       static unsigned char quiet_NaN() throw()
    00501       { return static_cast<unsigned char>(0); }
    00502       static unsigned char signaling_NaN() throw()
    00503       { return static_cast<unsigned char>(0); }
    00504       static unsigned char denorm_min() throw()
    00505       { return static_cast<unsigned char>(0); }
    00506
    00507       static const bool is_iec559 = false;
    00508       static const bool is_bounded = true;
    00509       static const bool is_modulo = true;
    00510
    00511       static const bool traps = __glibcxx_integral_traps;
    00512       static const bool tinyness_before = false;
    00513       static const float_round_style round_style = round_toward_zero;
    00514     };
    00515
    00516   template<>
    00517     struct numeric_limits<wchar_t>
    00518     {
    00519       static const bool is_specialized = true;
    00520
    00521       static wchar_t min() throw()
    00522       { return __glibcxx_min (wchar_t); }
    00523       static wchar_t max() throw()
    00524       { return __glibcxx_max (wchar_t); }
    00525
    00526       static const int digits = __glibcxx_digits (wchar_t);
    00527       static const int digits10 = __glibcxx_digits10 (wchar_t);
    00528       static const bool is_signed = __glibcxx_signed (wchar_t);
    00529       static const bool is_integer = true;
    00530       static const bool is_exact = true;
    00531       static const int radix = 2;
    00532       static wchar_t epsilon() throw()
    00533       { return 0; }
    00534       static wchar_t round_error() throw()
    00535       { return 0; }
    00536
    00537       static const int min_exponent = 0;
    00538       static const int min_exponent10 = 0;
    00539       static const int max_exponent = 0;
    00540       static const int max_exponent10 = 0;
    00541
    00542       static const bool has_infinity = false;
    00543       static const bool has_quiet_NaN = false;
    00544       static const bool has_signaling_NaN = false;
    00545       static const float_denorm_style has_denorm = denorm_absent;
    00546       static const bool has_denorm_loss = false;
    00547
    00548       static wchar_t infinity() throw()
    00549       { return wchar_t(); }
    00550       static wchar_t quiet_NaN() throw()
    00551       { return wchar_t(); }
    00552       static wchar_t signaling_NaN() throw()
    00553       { return wchar_t(); }
    00554       static wchar_t denorm_min() throw()
    00555       { return wchar_t(); }
    00556
    00557       static const bool is_iec559 = false;
    00558       static const bool is_bounded = true;
    00559       static const bool is_modulo = true;
    00560
    00561       static const bool traps = __glibcxx_integral_traps;
    00562       static const bool tinyness_before = false;
    00563       static const float_round_style round_style = round_toward_zero;
    00564     };
    00565
    00566   template<>
    00567     struct numeric_limits<short>
    00568     {
    00569       static const bool is_specialized = true;
    00570
    00571       static short min() throw()
    00572       { return -__SHRT_MAX__ - 1; }
    00573       static short max() throw()
    00574       { return __SHRT_MAX__; }
    00575
    00576       static const int digits = __glibcxx_digits (short);
    00577       static const int digits10 = __glibcxx_digits10 (short);
    00578       static const bool is_signed = true;
    00579       static const bool is_integer = true;
    00580       static const bool is_exact = true;
    00581       static const int radix = 2;
    00582       static short epsilon() throw()
    00583       { return 0; }
    00584       static short round_error() throw()
    00585       { return 0; }
    00586
    00587       static const int min_exponent = 0;
    00588       static const int min_exponent10 = 0;
    00589       static const int max_exponent = 0;
    00590       static const int max_exponent10 = 0;
    00591
    00592       static const bool has_infinity = false;
    00593       static const bool has_quiet_NaN = false;
    00594       static const bool has_signaling_NaN = false;
    00595       static const float_denorm_style has_denorm = denorm_absent;
    00596       static const bool has_denorm_loss = false;
    00597
    00598       static short infinity() throw()
    00599       { return short(); }
    00600       static short quiet_NaN() throw()
    00601       { return short(); }
    00602       static short signaling_NaN() throw()
    00603       { return short(); }
    00604       static short denorm_min() throw()
    00605       { return short(); }
    00606
    00607       static const bool is_iec559 = false;
    00608       static const bool is_bounded = true;
    00609       static const bool is_modulo = true;
    00610
    00611       static const bool traps = __glibcxx_integral_traps;
    00612       static const bool tinyness_before = false;
    00613       static const float_round_style round_style = round_toward_zero;
    00614     };
    00615
    00616   template<>
    00617     struct numeric_limits<unsigned short>
    00618     {
    00619       static const bool is_specialized = true;
    00620
    00621       static unsigned short min() throw()
    00622       { return 0; }
    00623       static unsigned short max() throw()
    00624       { return __SHRT_MAX__ * 2U + 1; }
    00625
    00626       static const int digits = __glibcxx_digits (unsigned short);
    00627       static const int digits10 = __glibcxx_digits10 (unsigned short);
    00628       static const bool is_signed = false;
    00629       static const bool is_integer = true;
    00630       static const bool is_exact = true;
    00631       static const int radix = 2;
    00632       static unsigned short epsilon() throw()
    00633       { return 0; }
    00634       static unsigned short round_error() throw()
    00635       { return 0; }
    00636
    00637       static const int min_exponent = 0;
    00638       static const int min_exponent10 = 0;
    00639       static const int max_exponent = 0;
    00640       static const int max_exponent10 = 0;
    00641
    00642       static const bool has_infinity = false;
    00643       static const bool has_quiet_NaN = false;
    00644       static const bool has_signaling_NaN = false;
    00645       static const float_denorm_style has_denorm = denorm_absent;
    00646       static const bool has_denorm_loss = false;
    00647
    00648       static unsigned short infinity() throw()
    00649       { return static_cast<unsigned short>(0); }
    00650       static unsigned short quiet_NaN() throw()
    00651       { return static_cast<unsigned short>(0); }
    00652       static unsigned short signaling_NaN() throw()
    00653       { return static_cast<unsigned short>(0); }
    00654       static unsigned short denorm_min() throw()
    00655       { return static_cast<unsigned short>(0); }
    00656
    00657       static const bool is_iec559 = false;
    00658       static const bool is_bounded = true;
    00659       static const bool is_modulo = true;
    00660
    00661       static const bool traps = __glibcxx_integral_traps;
    00662       static const bool tinyness_before = false;
    00663       static const float_round_style round_style = round_toward_zero;
    00664     };
    00665
    00666   template<>
    00667     struct numeric_limits<int>
    00668     {
    00669       static const bool is_specialized = true;
    00670
    00671       static int min() throw()
    00672       { return -__INT_MAX__ - 1; }
    00673       static int max() throw()
    00674       { return __INT_MAX__; }
    00675
    00676       static const int digits = __glibcxx_digits (int);
    00677       static const int digits10 = __glibcxx_digits10 (int);
    00678       static const bool is_signed = true;
    00679       static const bool is_integer = true;
    00680       static const bool is_exact = true;
    00681       static const int radix = 2;
    00682       static int epsilon() throw()
    00683       { return 0; }
    00684       static int round_error() throw()
    00685       { return 0; }
    00686
    00687       static const int min_exponent = 0;
    00688       static const int min_exponent10 = 0;
    00689       static const int max_exponent = 0;
    00690       static const int max_exponent10 = 0;
    00691
    00692       static const bool has_infinity = false;
    00693       static const bool has_quiet_NaN = false;
    00694       static const bool has_signaling_NaN = false;
    00695       static const float_denorm_style has_denorm = denorm_absent;
    00696       static const bool has_denorm_loss = false;
    00697
    00698       static int infinity() throw()
    00699       { return static_cast<int>(0); }
    00700       static int quiet_NaN() throw()
    00701       { return static_cast<int>(0); }
    00702       static int signaling_NaN() throw()
    00703       { return static_cast<int>(0); }
    00704       static int denorm_min() throw()
    00705       { return static_cast<int>(0); }
    00706
    00707       static const bool is_iec559 = false;
    00708       static const bool is_bounded = true;
    00709       static const bool is_modulo = true;
    00710
    00711       static const bool traps = __glibcxx_integral_traps;
    00712       static const bool tinyness_before = false;
    00713       static const float_round_style round_style = round_toward_zero;
    00714     };
    00715
    00716   template<>
    00717     struct numeric_limits<unsigned int>
    00718     {
    00719       static const bool is_specialized = true;
    00720
    00721       static unsigned int min() throw()
    00722       { return 0; }
    00723       static unsigned int max() throw()
    00724       { return __INT_MAX__ * 2U + 1; }
    00725
    00726       static const int digits = __glibcxx_digits (unsigned int);
    00727       static const int digits10 = __glibcxx_digits10 (unsigned int);
    00728       static const bool is_signed = false;
    00729       static const bool is_integer = true;
    00730       static const bool is_exact = true;
    00731       static const int radix = 2;
    00732       static unsigned int epsilon() throw()
    00733       { return 0; }
    00734       static unsigned int round_error() throw()
    00735       { return 0; }
    00736
    00737       static const int min_exponent = 0;
    00738       static const int min_exponent10 = 0;
    00739       static const int max_exponent = 0;
    00740       static const int max_exponent10 = 0;
    00741
    00742       static const bool has_infinity = false;
    00743       static const bool has_quiet_NaN = false;
    00744       static const bool has_signaling_NaN = false;
    00745       static const float_denorm_style has_denorm = denorm_absent;
    00746       static const bool has_denorm_loss = false;
    00747
    00748       static unsigned int infinity() throw()
    00749       { return static_cast<unsigned int>(0); }
    00750       static unsigned int quiet_NaN() throw()
    00751       { return static_cast<unsigned int>(0); }
    00752       static unsigned int signaling_NaN() throw()
    00753       { return static_cast<unsigned int>(0); }
    00754       static unsigned int denorm_min() throw()
    00755       { return static_cast<unsigned int>(0); }
    00756
    00757       static const bool is_iec559 = false;
    00758       static const bool is_bounded = true;
    00759       static const bool is_modulo = true;
    00760
    00761       static const bool traps = __glibcxx_integral_traps;
    00762       static const bool tinyness_before = false;
    00763       static const float_round_style round_style = round_toward_zero;
    00764     };
    00765
    00766   template<>
    00767     struct numeric_limits<long>
    00768     {
    00769       static const bool is_specialized = true;
    00770
    00771       static long min() throw()
    00772       { return -__LONG_MAX__ - 1; }
    00773       static long max() throw()
    00774       { return __LONG_MAX__; }
    00775
    00776       static const int digits = __glibcxx_digits (long);
    00777       static const int digits10 = __glibcxx_digits10 (long);
    00778       static const bool is_signed = true;
    00779       static const bool is_integer = true;
    00780       static const bool is_exact = true;
    00781       static const int radix = 2;
    00782       static long epsilon() throw()
    00783       { return 0; }
    00784       static long round_error() throw()
    00785       { return 0; }
    00786
    00787       static const int min_exponent = 0;
    00788       static const int min_exponent10 = 0;
    00789       static const int max_exponent = 0;
    00790       static const int max_exponent10 = 0;
    00791
    00792       static const bool has_infinity = false;
    00793       static const bool has_quiet_NaN = false;
    00794       static const bool has_signaling_NaN = false;
    00795       static const float_denorm_style has_denorm = denorm_absent;
    00796       static const bool has_denorm_loss = false;
    00797
    00798       static long infinity() throw()
    00799       { return static_cast<long>(0); }
    00800       static long quiet_NaN() throw()
    00801       { return static_cast<long>(0); }
    00802       static long signaling_NaN() throw()
    00803       { return static_cast<long>(0); }
    00804       static long denorm_min() throw()
    00805       { return static_cast<long>(0); }
    00806
    00807       static const bool is_iec559 = false;
    00808       static const bool is_bounded = true;
    00809       static const bool is_modulo = true;
    00810
    00811       static const bool traps = __glibcxx_integral_traps;
    00812       static const bool tinyness_before = false;
    00813       static const float_round_style round_style = round_toward_zero;
    00814     };
    00815
    00816   template<>
    00817     struct numeric_limits<unsigned long>
    00818     {
    00819       static const bool is_specialized = true;
    00820
    00821       static unsigned long min() throw()
    00822       { return 0; }
    00823       static unsigned long max() throw()
    00824       { return __LONG_MAX__ * 2UL + 1; }
    00825
    00826       static const int digits = __glibcxx_digits (unsigned long);
    00827       static const int digits10 = __glibcxx_digits10 (unsigned long);
    00828       static const bool is_signed = false;
    00829       static const bool is_integer = true;
    00830       static const bool is_exact = true;
    00831       static const int radix = 2;
    00832       static unsigned long epsilon() throw()
    00833       { return 0; }
    00834       static unsigned long round_error() throw()
    00835       { return 0; }
    00836
    00837       static const int min_exponent = 0;
    00838       static const int min_exponent10 = 0;
    00839       static const int max_exponent = 0;
    00840       static const int max_exponent10 = 0;
    00841
    00842       static const bool has_infinity = false;
    00843       static const bool has_quiet_NaN = false;
    00844       static const bool has_signaling_NaN = false;
    00845       static const float_denorm_style has_denorm = denorm_absent;
    00846       static const bool has_denorm_loss = false;
    00847
    00848       static unsigned long infinity() throw()
    00849       { return static_cast<unsigned long>(0); }
    00850       static unsigned long quiet_NaN() throw()
    00851       { return static_cast<unsigned long>(0); }
    00852       static unsigned long signaling_NaN() throw()
    00853       { return static_cast<unsigned long>(0); }
    00854       static unsigned long denorm_min() throw()
    00855       { return static_cast<unsigned long>(0); }
    00856
    00857       static const bool is_iec559 = false;
    00858       static const bool is_bounded = true;
    00859       static const bool is_modulo = true;
    00860
    00861       static const bool traps = __glibcxx_integral_traps;
    00862       static const bool tinyness_before = false;
    00863       static const float_round_style round_style = round_toward_zero;
    00864     };
    00865
    00866   template<>
    00867     struct numeric_limits<long long>
    00868     {
    00869       static const bool is_specialized = true;
    00870
    00871       static long long min() throw()
    00872       { return -__LONG_LONG_MAX__ - 1; }
    00873       static long long max() throw()
    00874       { return __LONG_LONG_MAX__; }
    00875
    00876       static const int digits = __glibcxx_digits (long long);
    00877       static const int digits10 = __glibcxx_digits10 (long long);
    00878       static const bool is_signed = true;
    00879       static const bool is_integer = true;
    00880       static const bool is_exact = true;
    00881       static const int radix = 2;
    00882       static long long epsilon() throw()
    00883       { return 0; }
    00884       static long long round_error() throw()
    00885       { return 0; }
    00886
    00887       static const int min_exponent = 0;
    00888       static const int min_exponent10 = 0;
    00889       static const int max_exponent = 0;
    00890       static const int max_exponent10 = 0;
    00891
    00892       static const bool has_infinity = false;
    00893       static const bool has_quiet_NaN = false;
    00894       static const bool has_signaling_NaN = false;
    00895       static const float_denorm_style has_denorm = denorm_absent;
    00896       static const bool has_denorm_loss = false;
    00897
    00898       static long long infinity() throw()
    00899       { return static_cast<long long>(0); }
    00900       static long long quiet_NaN() throw()
    00901       { return static_cast<long long>(0); }
    00902       static long long signaling_NaN() throw()
    00903       { return static_cast<long long>(0); }
    00904       static long long denorm_min() throw()
    00905       { return static_cast<long long>(0); }
    00906
    00907       static const bool is_iec559 = false;
    00908       static const bool is_bounded = true;
    00909       static const bool is_modulo = true;
    00910
    00911       static const bool traps = __glibcxx_integral_traps;
    00912       static const bool tinyness_before = false;
    00913       static const float_round_style round_style = round_toward_zero;
    00914     };
    00915
    00916   template<>
    00917     struct numeric_limits<unsigned long long>
    00918     {
    00919       static const bool is_specialized = true;
    00920
    00921       static unsigned long long min() throw()
    00922       { return 0; }
    00923       static unsigned long long max() throw()
    00924       { return __LONG_LONG_MAX__ * 2ULL + 1; }
    00925
    00926       static const int digits = __glibcxx_digits (unsigned long long);
    00927       static const int digits10 = __glibcxx_digits10 (unsigned long long);
    00928       static const bool is_signed = false;
    00929       static const bool is_integer = true;
    00930       static const bool is_exact = true;
    00931       static const int radix = 2;
    00932       static unsigned long long epsilon() throw()
    00933       { return 0; }
    00934       static unsigned long long round_error() throw()
    00935       { return 0; }
    00936
    00937       static const int min_exponent = 0;
    00938       static const int min_exponent10 = 0;
    00939       static const int max_exponent = 0;
    00940       static const int max_exponent10 = 0;
    00941
    00942       static const bool has_infinity = false;
    00943       static const bool has_quiet_NaN = false;
    00944       static const bool has_signaling_NaN = false;
    00945       static const float_denorm_style has_denorm = denorm_absent;
    00946       static const bool has_denorm_loss = false;
    00947
    00948       static unsigned long long infinity() throw()
    00949       { return static_cast<unsigned long long>(0); }
    00950       static unsigned long long quiet_NaN() throw()
    00951       { return static_cast<unsigned long long>(0); }
    00952       static unsigned long long signaling_NaN() throw()
    00953       { return static_cast<unsigned long long>(0); }
    00954       static unsigned long long denorm_min() throw()
    00955       { return static_cast<unsigned long long>(0); }
    00956
    00957       static const bool is_iec559 = false;
    00958       static const bool is_bounded = true;
    00959       static const bool is_modulo = true;
    00960
    00961       static const bool traps = __glibcxx_integral_traps;
    00962       static const bool tinyness_before = false;
    00963       static const float_round_style round_style = round_toward_zero;
    00964     };
    00965
    00966   template<>
    00967     struct numeric_limits<float>
    00968     {
    00969       static const bool is_specialized = true;
    00970
    00971       static float min() throw()
    00972       { return __FLT_MIN__; }
    00973       static float max() throw()
    00974       { return __FLT_MAX__; }
    00975
    00976       static const int digits = __FLT_MANT_DIG__;
    00977       static const int digits10 = __FLT_DIG__;
    00978       static const bool is_signed = true;
    00979       static const bool is_integer = false;
    00980       static const bool is_exact = false;
    00981       static const int radix = __FLT_RADIX__;
    00982       static float epsilon() throw()
    00983       { return __FLT_EPSILON__; }
    00984       static float round_error() throw()
    00985       { return 0.5F; }
    00986
    00987       static const int min_exponent = __FLT_MIN_EXP__;
    00988       static const int min_exponent10 = __FLT_MIN_10_EXP__;
    00989       static const int max_exponent = __FLT_MAX_EXP__;
    00990       static const int max_exponent10 = __FLT_MAX_10_EXP__;
    00991
    00992       static const bool has_infinity = __FLT_HAS_INFINITY__;
    00993       static const bool has_quiet_NaN = __FLT_HAS_QUIET_NAN__;
    00994       static const bool has_signaling_NaN = has_quiet_NaN;
    00995       static const float_denorm_style has_denorm
    00996     = __FLT_DENORM_MIN__ ? denorm_present : denorm_absent;
    00997       static const bool has_denorm_loss = __glibcxx_float_has_denorm_loss;
    00998
    00999       static float infinity() throw()
    01000       { return __builtin_huge_valf (); }
    01001       static float quiet_NaN() throw()
    01002       { return __builtin_nanf (""); }
    01003       static float signaling_NaN() throw()
    01004       { return __builtin_nansf (""); }
    01005       static float denorm_min() throw()
    01006       { return __FLT_DENORM_MIN__; }
    01007
    01008       static const bool is_iec559
    01009     = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
    01010       static const bool is_bounded = true;
    01011       static const bool is_modulo = false;
    01012
    01013       static const bool traps = __glibcxx_float_traps;
    01014       static const bool tinyness_before = __glibcxx_float_tinyness_before;
    01015       static const float_round_style round_style = round_to_nearest;
    01016     };
    01017
    01018 #undef __glibcxx_float_has_denorm_loss
    01019 #undef __glibcxx_float_traps
    01020 #undef __glibcxx_float_tinyness_before
    01021
    01022   template<>
    01023     struct numeric_limits<double>
    01024     {
    01025       static const bool is_specialized = true;
    01026
    01027       static double min() throw()
    01028       { return __DBL_MIN__; }
    01029       static double max() throw()
    01030       { return __DBL_MAX__; }
    01031
    01032       static const int digits = __DBL_MANT_DIG__;
    01033       static const int digits10 = __DBL_DIG__;
    01034       static const bool is_signed = true;
    01035       static const bool is_integer = false;
    01036       static const bool is_exact = false;
    01037       static const int radix = __FLT_RADIX__;
    01038       static double epsilon() throw()
    01039       { return __DBL_EPSILON__; }
    01040       static double round_error() throw()
    01041       { return 0.5; }
    01042
    01043       static const int min_exponent = __DBL_MIN_EXP__;
    01044       static const int min_exponent10 = __DBL_MIN_10_EXP__;
    01045       static const int max_exponent = __DBL_MAX_EXP__;
    01046       static const int max_exponent10 = __DBL_MAX_10_EXP__;
    01047
    01048       static const bool has_infinity = __DBL_HAS_INFINITY__;
    01049       static const bool has_quiet_NaN = __DBL_HAS_QUIET_NAN__;
    01050       static const bool has_signaling_NaN = has_quiet_NaN;
    01051       static const float_denorm_style has_denorm
    01052     = __DBL_DENORM_MIN__ ? denorm_present : denorm_absent;
    01053       static const bool has_denorm_loss = __glibcxx_double_has_denorm_loss;
    01054
    01055       static double infinity() throw()
    01056       { return __builtin_huge_val(); }
    01057       static double quiet_NaN() throw()
    01058       { return __builtin_nan (""); }
    01059       static double signaling_NaN() throw()
    01060       { return __builtin_nans (""); }
    01061       static double denorm_min() throw()
    01062       { return __DBL_DENORM_MIN__; }
    01063
    01064       static const bool is_iec559
    01065     = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
    01066       static const bool is_bounded = true;
    01067       static const bool is_modulo = false;
    01068
    01069       static const bool traps = __glibcxx_double_traps;
    01070       static const bool tinyness_before = __glibcxx_double_tinyness_before;
    01071       static const float_round_style round_style = round_to_nearest;
    01072     };
    01073
    01074 #undef __glibcxx_double_has_denorm_loss
    01075 #undef __glibcxx_double_traps
    01076 #undef __glibcxx_double_tinyness_before
    01077
    01078   template<>
    01079     struct numeric_limits<long double>
    01080     {
    01081       static const bool is_specialized = true;
    01082
    01083       static long double min() throw()
    01084       { return __LDBL_MIN__; }
    01085       static long double max() throw()
    01086       { return __LDBL_MAX__; }
    01087
    01088       static const int digits = __LDBL_MANT_DIG__;
    01089       static const int digits10 = __LDBL_DIG__;
    01090       static const bool is_signed = true;
    01091       static const bool is_integer = false;
    01092       static const bool is_exact = false;
    01093       static const int radix = __FLT_RADIX__;
    01094       static long double epsilon() throw()
    01095       { return __LDBL_EPSILON__; }
    01096       static long double round_error() throw()
    01097       { return 0.5L; }
    01098
    01099       static const int min_exponent = __LDBL_MIN_EXP__;
    01100       static const int min_exponent10 = __LDBL_MIN_10_EXP__;
    01101       static const int max_exponent = __LDBL_MAX_EXP__;
    01102       static const int max_exponent10 = __LDBL_MAX_10_EXP__;
    01103
    01104       static const bool has_infinity = __LDBL_HAS_INFINITY__;
    01105       static const bool has_quiet_NaN = __LDBL_HAS_QUIET_NAN__;
    01106       static const bool has_signaling_NaN = has_quiet_NaN;
    01107       static const float_denorm_style has_denorm
    01108     = __LDBL_DENORM_MIN__ ? denorm_present : denorm_absent;
    01109       static const bool has_denorm_loss
    01110     = __glibcxx_long_double_has_denorm_loss;
    01111
    01112       static long double infinity() throw()
    01113       { return __builtin_huge_vall (); }
    01114       static long double quiet_NaN() throw()
    01115       { return __builtin_nanl (""); }
    01116       static long double signaling_NaN() throw()
    01117       { return __builtin_nansl (""); }
    01118       static long double denorm_min() throw()
    01119       { return __LDBL_DENORM_MIN__; }
    01120
    01121       static const bool is_iec559
    01122     = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
    01123       static const bool is_bounded = true;
    01124       static const bool is_modulo = false;
    01125
    01126       static const bool traps = __glibcxx_long_double_traps;
    01127       static const bool tinyness_before = __glibcxx_long_double_tinyness_before;
    01128       static const float_round_style round_style = round_to_nearest;
    01129     };
    01130
    01131 #undef __glibcxx_long_double_has_denorm_loss
    01132 #undef __glibcxx_long_double_traps
    01133 #undef __glibcxx_long_double_tinyness_before
    01134
    01135 } // namespace std
    01136
    01137 #undef __glibcxx_signed
    01138 #undef __glibcxx_min
    01139 #undef __glibcxx_max
    01140 #undef __glibcxx_digits
    01141 #undef __glibcxx_digits10
    01142
    01143 #endif // _GLIBCXX_NUMERIC_LIMITS