/home/ntakagi/work/STLport-5.1.5/stlport/stl/_limits.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 /* NOTE: This may be not portable code. Parts of numeric_limits<> are
00020  * inherently machine-dependent.  At present this file is suitable
00021  * for the MIPS, SPARC, Alpha and ia32 architectures.
00022  */
00023 
00024 #ifndef _STLP_INTERNAL_LIMITS
00025 #define _STLP_INTERNAL_LIMITS
00026 
00027 #ifndef _STLP_CLIMITS
00028 #  include <climits>
00029 #endif
00030 
00031 #ifndef _STLP_CFLOAT
00032 #  include <cfloat>
00033 #endif
00034 
00035 #if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_INTERNAL_CWCHAR)
00036 #  include <stl/_cwchar.h>
00037 #endif
00038 
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 enum float_round_style {
00042   round_indeterminate       = -1,
00043   round_toward_zero         =  0,
00044   round_to_nearest          =  1,
00045   round_toward_infinity     =  2,
00046   round_toward_neg_infinity =  3
00047 };
00048 
00049 enum float_denorm_style {
00050   denorm_indeterminate = -1,
00051   denorm_absent        =  0,
00052   denorm_present       =  1
00053 };
00054 
00055 _STLP_MOVE_TO_PRIV_NAMESPACE
00056 
00057 // Base class for all specializations of numeric_limits.
00058 template <class __number>
00059 class _Numeric_limits_base {
00060 public:
00061 
00062   static __number (_STLP_CALL min)() _STLP_NOTHROW { return __number(); }
00063   static __number (_STLP_CALL max)() _STLP_NOTHROW { return __number(); }
00064 
00065 #if defined ( _STLP_STATIC_CONST_INIT_BUG)
00066   enum {
00067 #else
00068   static const int
00069 #endif
00070 
00071   digits = 0,
00072   digits10 = 0,
00073   radix = 0,
00074   min_exponent = 0,
00075   min_exponent10 = 0,
00076   max_exponent = 0,
00077   max_exponent10 = 0
00078 
00079 #if defined ( _STLP_STATIC_CONST_INIT_BUG)
00080   ,
00081   has_denorm = denorm_absent,
00082   round_style = round_toward_zero,
00083 #else
00084   ;
00085   static const float_denorm_style has_denorm =  denorm_absent;
00086   static const float_round_style round_style = round_toward_zero;
00087   static const bool
00088 #endif
00089 
00090     is_specialized = false,
00091     is_signed  = false,
00092     is_integer = false,
00093     is_exact = false,
00094     has_infinity = false,
00095     has_quiet_NaN = false,
00096     has_signaling_NaN = false,
00097     has_denorm_loss = false,
00098     is_iec559 = false,
00099     is_bounded = false,
00100     is_modulo = false,
00101     traps = false,
00102     tinyness_before = false
00103 #if defined ( _STLP_STATIC_CONST_INIT_BUG)
00104   }
00105 #endif
00106   ;
00107 
00108   static __number _STLP_CALL epsilon() _STLP_NOTHROW     { return __number(); }
00109   static __number _STLP_CALL round_error() _STLP_NOTHROW { return __number(); }
00110 
00111   static __number _STLP_CALL infinity() _STLP_NOTHROW      { return __number(); }
00112   static __number _STLP_CALL quiet_NaN() _STLP_NOTHROW     { return __number(); }
00113   static __number _STLP_CALL signaling_NaN() _STLP_NOTHROW { return __number(); }
00114   static __number _STLP_CALL denorm_min() _STLP_NOTHROW    { return __number(); }
00115 };
00116 
00117 // Base class for integers.
00118 
00119 #ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
00120 #  ifdef _STLP_LONG_LONG
00121 #    define _STLP_LIMITS_MIN_TYPE _STLP_LONG_LONG
00122 #    define _STLP_LIMITS_MAX_TYPE unsigned _STLP_LONG_LONG
00123 #  else
00124 #    define _STLP_LIMITS_MIN_TYPE long
00125 #    define _STLP_LIMITS_MAX_TYPE unsigned long
00126 #  endif
00127 #else
00128 #  define _STLP_LIMITS_MIN_TYPE _Int
00129 #  define _STLP_LIMITS_MAX_TYPE _Int
00130 #endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
00131 
00132 template <class _Int,
00133           _STLP_LIMITS_MIN_TYPE __imin,
00134           _STLP_LIMITS_MAX_TYPE __imax,
00135           int __idigits, bool __ismod>
00136 class _Integer_limits : public _Numeric_limits_base<_Int> {
00137 public:
00138 
00139   static _Int (_STLP_CALL min) () _STLP_NOTHROW { return (_Int)__imin; }
00140   static _Int (_STLP_CALL max) () _STLP_NOTHROW { return (_Int)__imax; }
00141 
00142 #if defined (_STLP_STATIC_CONST_INIT_BUG)
00143   enum {
00144 #else
00145   static const int
00146 #endif
00147   digits = (__idigits < 0) ?
00148   ((int)((sizeof(_Int) * (CHAR_BIT))) - ((__imin == 0) ? 0 : 1))
00149   : (__idigits),
00150   digits10 = (digits * 301UL) / 1000,
00151   radix = 2
00152 #if !defined (_STLP_STATIC_CONST_INIT_BUG)
00153   ;
00154   static const bool
00155 #else
00156   ,
00157 #endif
00158   is_specialized = true,
00159   is_signed = (__imin != 0),
00160   is_integer = true,
00161   is_exact = true,
00162   is_bounded = true,
00163   is_modulo = __ismod
00164 #if defined ( _STLP_STATIC_CONST_INIT_BUG)
00165   }
00166 #endif
00167   ;
00168 };
00169 
00170 // Base class for floating-point numbers.
00171 template <class __number,
00172          int __Digits, int __Digits10,
00173          int __MinExp, int __MaxExp,
00174          int __MinExp10, int __MaxExp10,
00175          bool __IsIEC559,
00176          float_round_style __RoundStyle>
00177 class _Floating_limits : public _Numeric_limits_base<__number> {
00178 public:
00179 
00180 #if defined (_STLP_STATIC_CONST_INIT_BUG)
00181   enum {
00182 #else
00183   static const int
00184 #endif
00185 
00186   digits = __Digits,
00187   digits10 = __Digits10,
00188 
00189   radix = (  FLT_RADIX /* 2 */ ),
00190   min_exponent = __MinExp,
00191   max_exponent = __MaxExp,
00192   min_exponent10 = __MinExp10,
00193   max_exponent10 = __MaxExp10
00194 
00195 #if defined (_STLP_STATIC_CONST_INIT_BUG)
00196   ,
00197   has_denorm = denorm_indeterminate,
00198   round_style = __RoundStyle,
00199 #else
00200   ;
00201   static const float_denorm_style has_denorm = denorm_indeterminate;
00202   static const float_round_style round_style = __RoundStyle;
00203   static const bool
00204 #endif
00205 
00206   is_specialized = true,
00207   is_signed = true,
00208 
00209   //IEC 559 specify the floating point representation of
00210   //infinity, quiet and signaling Not a Number. Not supporting
00211   //it is consider as not being able to grant those values.
00212 #if (defined (_STLP_MSVC) && (_STLP_MSVC < 1300))
00213   //MSVC 6 do not fully support IEC 599 but grant a good infinity value.
00214   has_infinity      = true,
00215 #else
00216   has_infinity      = __IsIEC559,
00217 #endif
00218   has_quiet_NaN     = __IsIEC559,
00219   has_signaling_NaN = __IsIEC559,
00220 
00221   has_denorm_loss   =  false,
00222   is_iec559      =  __IsIEC559,
00223   is_bounded     =  true,
00224   traps          =  true,
00225   tinyness_before=  false
00226 
00227 #if defined (_STLP_STATIC_CONST_INIT_BUG)
00228   }
00229 #endif
00230   ;
00231 };
00232 
00233 _STLP_MOVE_TO_STD_NAMESPACE
00234 
00235 // Class numeric_limits
00236 
00237 // The unspecialized class.
00238 
00239 template<class _Tp>
00240 class numeric_limits : public _STLP_PRIV _Numeric_limits_base<_Tp> {};
00241 
00242 // Specializations for all built-in integral types.
00243 
00244 #if !defined (_STLP_NO_BOOL)
00245 _STLP_TEMPLATE_NULL
00246 class numeric_limits<bool>
00247   : public _STLP_PRIV _Integer_limits<bool, false, true, 1, false>
00248 {};
00249 #endif /* _STLP_NO_BOOL */
00250 
00251 _STLP_TEMPLATE_NULL
00252 class numeric_limits<char>
00253   : public _STLP_PRIV _Integer_limits<char, CHAR_MIN, CHAR_MAX, -1, true>
00254 {};
00255 
00256 #if !defined (_STLP_NO_SIGNED_BUILTINS)
00257 _STLP_TEMPLATE_NULL
00258 class numeric_limits<signed char>
00259   : public _STLP_PRIV _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX, -1, true>
00260 {};
00261 #endif
00262 
00263 _STLP_TEMPLATE_NULL
00264 class numeric_limits<unsigned char>
00265   : public _STLP_PRIV _Integer_limits<unsigned char, 0, UCHAR_MAX, -1, true>
00266 {};
00267 
00268 #if !(defined (_STLP_NO_WCHAR_T) || defined (_STLP_WCHAR_T_IS_USHORT))
00269 
00270 _STLP_TEMPLATE_NULL
00271 class numeric_limits<wchar_t>
00272   : public _STLP_PRIV _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
00273 {};
00274 
00275 #endif
00276 
00277 _STLP_TEMPLATE_NULL
00278 class numeric_limits<short>
00279   : public _STLP_PRIV _Integer_limits<short, SHRT_MIN, SHRT_MAX, -1, true>
00280 {};
00281 
00282 _STLP_TEMPLATE_NULL
00283 class numeric_limits<unsigned short>
00284   : public _STLP_PRIV _Integer_limits<unsigned short, 0, USHRT_MAX, -1, true>
00285 {};
00286 
00287 #if defined (__xlC__) && (__xlC__ == 0x500)
00288 #  undef INT_MIN
00289 #  define INT_MIN -2147483648
00290 #endif
00291 
00292 _STLP_TEMPLATE_NULL
00293 class numeric_limits<int>
00294   : public _STLP_PRIV _Integer_limits<int, INT_MIN, INT_MAX, -1, true>
00295 {};
00296 
00297 _STLP_TEMPLATE_NULL
00298 class numeric_limits<unsigned int>
00299   : public _STLP_PRIV _Integer_limits<unsigned int, 0, UINT_MAX, -1, true>
00300 {};
00301 
00302 _STLP_TEMPLATE_NULL
00303 class numeric_limits<long>
00304   : public _STLP_PRIV _Integer_limits<long, LONG_MIN, LONG_MAX, -1, true>
00305 {};
00306 
00307 _STLP_TEMPLATE_NULL
00308 class numeric_limits<unsigned long>
00309   : public _STLP_PRIV _Integer_limits<unsigned long, 0, ULONG_MAX, -1, true>
00310 {};
00311 
00312 #if defined (_STLP_LONG_LONG)
00313 
00314 #  if defined (_STLP_MSVC) || defined (__BORLANDC__)
00315 #    define LONGLONG_MAX     0x7fffffffffffffffi64
00316 #    define LONGLONG_MIN     (-LONGLONG_MAX-1i64)
00317 #    define ULONGLONG_MAX    0xffffffffffffffffUi64
00318 #  else
00319 #    ifndef LONGLONG_MAX
00320 #      define LONGLONG_MAX   0x7fffffffffffffffLL
00321 #    endif
00322 #    ifndef LONGLONG_MIN
00323 #      define LONGLONG_MIN   (-LONGLONG_MAX-1LL)
00324 #    endif
00325 #    ifndef ULONGLONG_MAX
00326 #      define ULONGLONG_MAX  0xffffffffffffffffULL
00327 #    endif
00328 #  endif
00329 
00330 #  if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ <= 96)
00331 
00332 _STLP_TEMPLATE_NULL
00333 class numeric_limits<_STLP_LONG_LONG>
00334   : public _STLP_PRIV _Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
00335 {};
00336 
00337 _STLP_TEMPLATE_NULL
00338 class numeric_limits<unsigned _STLP_LONG_LONG>
00339   : public _STLP_PRIV _Integer_limits<unsigned _STLP_LONG_LONG, 0, ULONGLONG_MAX, -1, true>
00340 {};
00341 #  else /* gcc 2.97 (after 2000-11-01), 2.98, 3.0 */
00342 /*
00343  newest gcc has new mangling scheme, that has problem
00344  with generating name [instantiated] of template specialization like
00345  _Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
00346                                   ~~~~~~~~~~~~  ~~~~~~~~~~~~
00347  Below is code that solve this problem.
00348    - ptr
00349  */
00350 _STLP_TEMPLATE_NULL
00351 class numeric_limits<_STLP_LONG_LONG>
00352   : public _STLP_PRIV _Numeric_limits_base<_STLP_LONG_LONG> {
00353 public:
00354 
00355   static _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return LONGLONG_MIN; }
00356   static _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return LONGLONG_MAX; }
00357 
00358 #    if defined ( _STLP_STATIC_CONST_INIT_BUG)
00359   enum {
00360 #    else
00361   static const int
00362 #    endif
00363   digits = ((int)((sizeof(_STLP_LONG_LONG) * (CHAR_BIT))) - 1),
00364   digits10 = (digits * 301UL) / 1000,
00365   radix = 2
00366 #    if ! defined (_STLP_STATIC_CONST_INIT_BUG)
00367   ;
00368   static const bool
00369 #    else
00370   ,
00371 #    endif
00372   is_specialized = true,
00373   is_signed = true,
00374   is_integer = true,
00375   is_exact = true,
00376   is_bounded = true,
00377   is_modulo = true
00378 #    if defined (_STLP_STATIC_CONST_INIT_BUG)
00379   }
00380 #    endif
00381   ;
00382 };
00383 
00384 _STLP_TEMPLATE_NULL
00385 class numeric_limits<unsigned _STLP_LONG_LONG>
00386   : public _STLP_PRIV _Numeric_limits_base<unsigned _STLP_LONG_LONG> {
00387 public:
00388 
00389   static unsigned _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return 0ULL; }
00390   static unsigned _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return ULONGLONG_MAX; }
00391 
00392 #    if defined (_STLP_STATIC_CONST_INIT_BUG)
00393   enum {
00394 #    else
00395   static const int
00396 #    endif
00397   digits = ((int)((sizeof(unsigned _STLP_LONG_LONG) * (CHAR_BIT)))),
00398   digits10 = (digits * 301UL) / 1000,
00399   radix = 2
00400 #    if ! defined (_STLP_STATIC_CONST_INIT_BUG)
00401   ;
00402   static const bool
00403 #    else
00404   ,
00405 #    endif
00406   is_specialized = true,
00407   is_signed = false,
00408   is_integer = true,
00409   is_exact = true,
00410   is_bounded = true,
00411   is_modulo = true
00412 #    if defined ( _STLP_STATIC_CONST_INIT_BUG)
00413   }
00414 #    endif
00415   ;
00416 };
00417 
00418 #  endif /* __GNUC__ > 2000-11-01 */
00419 
00420 #endif /* _STLP_LONG_LONG */
00421 
00422 _STLP_MOVE_TO_PRIV_NAMESPACE
00423 
00424 // Specializations for all built-in floating-point types.
00425 template <class __dummy>
00426 class _LimG {
00427 public:
00428   static float _STLP_CALL get_F_inf();
00429   static float _STLP_CALL get_F_qNaN();
00430   static float _STLP_CALL get_F_sNaN();
00431   static double _STLP_CALL get_D_inf();
00432   static double _STLP_CALL get_D_qNaN();
00433   static double _STLP_CALL get_D_sNaN();
00434 
00435 #if !defined (_STLP_NO_LONG_DOUBLE)
00436   static long double _STLP_CALL get_LD_inf();
00437   static long double _STLP_CALL get_LD_qNaN();
00438   static long double _STLP_CALL get_LD_sNaN();
00439 #endif
00440 };
00441 
00442 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00443 _STLP_EXPORT_TEMPLATE_CLASS _LimG<bool>;
00444 #endif
00445 
00446 _STLP_MOVE_TO_STD_NAMESPACE
00447 
00448 _STLP_TEMPLATE_NULL
00449 class numeric_limits<float>
00450   : public _STLP_PRIV _Floating_limits<float,
00451                                         FLT_MANT_DIG,   // Binary digits of precision
00452                                         FLT_DIG,        // Decimal digits of precision
00453                                         FLT_MIN_EXP,    // Minimum exponent
00454                                         FLT_MAX_EXP,    // Maximum exponent
00455                                         FLT_MIN_10_EXP, // Minimum base 10 exponent
00456                                         FLT_MAX_10_EXP, // Maximum base 10 exponent
00457 #if defined (_STLP_NO_IEC559_SUPPORT)
00458                                         false,          // do not conform to iec559
00459 #else
00460                                         true,           // conforms to iec559
00461 #endif
00462                                         round_to_nearest> {
00463 public:
00464   static float (_STLP_CALL min) () _STLP_NOTHROW { return FLT_MIN; }
00465   static float _STLP_CALL denorm_min() _STLP_NOTHROW { return FLT_MIN; }
00466   static float (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return FLT_MAX; }
00467   static float _STLP_CALL epsilon() _STLP_NOTHROW { return FLT_EPSILON; }
00468   static float _STLP_CALL round_error() _STLP_NOTHROW { return 0.5f; } // Units: ulps.
00469   static  float _STLP_CALL infinity() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_F_inf(); }
00470   static  float _STLP_CALL quiet_NaN() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_F_qNaN(); }
00471   static  float _STLP_CALL signaling_NaN() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_F_sNaN(); }
00472 };
00473 
00474 _STLP_TEMPLATE_NULL
00475 class numeric_limits<double>
00476   : public _STLP_PRIV _Floating_limits<double,
00477                                         DBL_MANT_DIG,   // Binary digits of precision
00478                                         DBL_DIG,        // Decimal digits of precision
00479                                         DBL_MIN_EXP,    // Minimum exponent
00480                                         DBL_MAX_EXP,    // Maximum exponent
00481                                         DBL_MIN_10_EXP, // Minimum base 10 exponent
00482                                         DBL_MAX_10_EXP, // Maximum base 10 exponent
00483 #if defined (_STLP_NO_IEC559_SUPPORT)
00484                                         false,          // do not conform to iec559
00485 #else
00486                                         true,           // conforms to iec559
00487 #endif
00488                                         round_to_nearest> {
00489 public:
00490   static double (_STLP_CALL min)() _STLP_NOTHROW { return DBL_MIN; }
00491   static double _STLP_CALL denorm_min() _STLP_NOTHROW { return DBL_MIN; }
00492   static double (_STLP_CALL max)() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return DBL_MAX; }
00493   static double _STLP_CALL epsilon() _STLP_NOTHROW { return DBL_EPSILON; }
00494   static double _STLP_CALL round_error() _STLP_NOTHROW { return 0.5; } // Units: ulps.
00495   static  double _STLP_CALL infinity() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_D_inf(); }
00496   static  double _STLP_CALL quiet_NaN() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_D_qNaN(); }
00497   static  double _STLP_CALL signaling_NaN() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_D_sNaN(); }
00498 };
00499 
00500 #if !defined (_STLP_NO_LONG_DOUBLE)
00501 
00502 _STLP_TEMPLATE_NULL
00503 class numeric_limits<long double>
00504   : public _STLP_PRIV _Floating_limits<long double,
00505                                         LDBL_MANT_DIG,  // Binary digits of precision
00506                                         LDBL_DIG,       // Decimal digits of precision
00507                                         LDBL_MIN_EXP,   // Minimum exponent
00508                                         LDBL_MAX_EXP,   // Maximum exponent
00509                                         LDBL_MIN_10_EXP,// Minimum base 10 exponent
00510                                         LDBL_MAX_10_EXP,// Maximum base 10 exponent
00511                                         false,          // do not conform to iec559
00512                                         round_to_nearest> {
00513 public:
00514   static long double (_STLP_CALL min) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
00515   static long double _STLP_CALL denorm_min() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
00516   static long double (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MAX; }
00517   static long double _STLP_CALL epsilon() _STLP_NOTHROW { return LDBL_EPSILON; }
00518   static long double _STLP_CALL round_error() _STLP_NOTHROW { return 4; } // Units: ulps.
00519   static long double _STLP_CALL infinity() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_LD_inf(); }
00520   static long double _STLP_CALL quiet_NaN() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_LD_qNaN(); }
00521   static long double _STLP_CALL signaling_NaN() _STLP_NOTHROW { return _STLP_PRIV _LimG<bool>::get_LD_sNaN(); }
00522 };
00523 
00524 #endif
00525 
00526 // We write special values (Inf and NaN) as bit patterns and
00527 // cast the the appropriate floating-point types.
00528 _STLP_END_NAMESPACE
00529 
00530 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
00531 #  include <stl/_limits.c>
00532 #endif
00533 
00534 #endif
00535 
00536 // Local Variables:
00537 // mode:C++
00538 // End:



Generated on Mon Mar 10 15:32:27 2008 by  doxygen 1.5.1