epoc32/include/stdapis/stlport/stl/_limits.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     3  * Copyright (c) 1997
     4  * Silicon Graphics Computer Systems, Inc.
     5  *
     6  * Copyright (c) 1999 
     7  * Boris Fomitchev
     8  *
     9  * This material is provided "as is", with absolutely no warranty expressed
    10  * or implied. Any use is at your own risk.
    11  *
    12  * Permission to use or copy this software for any purpose is hereby granted 
    13  * without fee, provided the above notices are retained on all copies.
    14  * Permission to modify the code and to distribute modified code is granted,
    15  * provided the above notices are retained, and a notice that the code was
    16  * modified is included with the above copyright notice.
    17  *
    18  */
    19 
    20 /* NOTE: This may be not portable code. Parts of numeric_limits<> are
    21  * inherently machine-dependent.  At present this file is suitable
    22  * for the MIPS, SPARC, Alpha and ia32 architectures.
    23  */
    24 
    25 #ifndef _STLP_INTERNAL_LIMITS_H
    26 # define _STLP_INTERNAL_LIMITS_H
    27 
    28 #ifndef _STLP_CLIMITS
    29 # include <climits>
    30 #endif
    31 
    32 #ifndef _STLP_CFLOAT
    33 # include <cfloat>
    34 #endif
    35 
    36 #if !defined (_STLP_NO_WCHAR_T) && !defined (_STLP_CWCHAR_H)
    37 # include <stl/_cwchar.h>
    38 #endif
    39 
    40 _STLP_BEGIN_NAMESPACE
    41 
    42 enum float_round_style {
    43   round_indeterminate       = -1,
    44   round_toward_zero         =  0,
    45   round_to_nearest          =  1,
    46   round_toward_infinity     =  2,
    47   round_toward_neg_infinity =  3
    48 };
    49 
    50 enum float_denorm_style {
    51   denorm_indeterminate = -1,
    52   denorm_absent        =  0,
    53   denorm_present       =  1
    54 };
    55 
    56 // Base class for all specializations of numeric_limits.
    57 
    58 template <class __number>
    59 class _Numeric_limits_base {
    60 public:
    61 
    62   static __number (_STLP_CALL min)() _STLP_NOTHROW { return __number(); }
    63   static __number (_STLP_CALL max)() _STLP_NOTHROW { return __number(); }
    64 
    65 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
    66   enum {
    67 # else
    68   static const int 
    69 # endif
    70   
    71   digits = 0,
    72   digits10 = 0,
    73   radix = 0,
    74   min_exponent = 0,
    75   min_exponent10 = 0,
    76   max_exponent = 0,
    77   max_exponent10 = 0
    78 
    79 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
    80   ,  
    81   has_denorm = denorm_absent,
    82   round_style = round_toward_zero,
    83 # else
    84   ;
    85   static const float_denorm_style has_denorm =  denorm_absent;
    86   static const float_round_style round_style = round_toward_zero;
    87   static const bool 
    88 # endif
    89 
    90     is_specialized = false,
    91     is_signed  = false,
    92     is_integer = false,
    93     is_exact = false,
    94     has_infinity = false,
    95     has_quiet_NaN = false,
    96     has_signaling_NaN = false,
    97     has_denorm_loss = false,
    98     is_iec559 = false,
    99     is_bounded = false,
   100     is_modulo = false,
   101     traps = false,
   102     tinyness_before = false
   103 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   104   }
   105 # endif
   106   ;
   107     
   108   static __number _STLP_CALL epsilon() _STLP_NOTHROW     { return __number(); }
   109   static __number _STLP_CALL round_error() _STLP_NOTHROW { return __number(); }
   110 
   111   static __number _STLP_CALL infinity() _STLP_NOTHROW      { return __number(); }
   112   static __number _STLP_CALL quiet_NaN() _STLP_NOTHROW     { return __number(); }
   113   static __number _STLP_CALL signaling_NaN() _STLP_NOTHROW { return __number(); }
   114   static __number _STLP_CALL denorm_min() _STLP_NOTHROW    { return __number(); }
   115 
   116 
   117 };
   118 
   119 // Base class for integers.
   120 
   121 # ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
   122 #  ifdef _STLP_LONG_LONG
   123 #   define _STLP_LIMITS_MIN_TYPE _STLP_LONG_LONG
   124 #   define _STLP_LIMITS_MAX_TYPE unsigned _STLP_LONG_LONG
   125 #  else
   126 #   define _STLP_LIMITS_MIN_TYPE long
   127 #   define _STLP_LIMITS_MAX_TYPE unsigned long
   128 #  endif
   129 # else
   130 #   define _STLP_LIMITS_MIN_TYPE _Int
   131 #   define _STLP_LIMITS_MAX_TYPE _Int
   132 # endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
   133 
   134 template <class _Int,
   135           _STLP_LIMITS_MIN_TYPE __imin,
   136           _STLP_LIMITS_MAX_TYPE __imax,
   137           int __idigits, bool __ismod>
   138 class _Integer_limits : public _Numeric_limits_base<_Int> 
   139 {
   140 public:
   141 
   142   static _Int (_STLP_CALL min) () _STLP_NOTHROW { return (_Int)__imin; }
   143   static _Int (_STLP_CALL max) () _STLP_NOTHROW { return (_Int)__imax; }
   144 
   145 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   146   enum {
   147 # else
   148   static const int 
   149 # endif  
   150   digits = (__idigits < 0) ?
   151   ((int)((sizeof(_Int) * (CHAR_BIT))) - ((__imin == 0) ? 0 : 1))
   152   : (__idigits),
   153   digits10 = (digits * 301UL) / 1000,
   154   radix = 2
   155 # if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
   156   ;
   157   static const bool
   158 # else
   159   ,
   160 # endif
   161   is_specialized = true,
   162   is_signed = (__imin != 0),
   163   is_integer = true,
   164   is_exact = true,
   165   is_bounded = true,
   166   is_modulo = __ismod
   167 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   168   }
   169 # endif
   170   ;
   171 };
   172 
   173 // Base class for floating-point numbers.
   174 template <class __number,
   175          int __Digits, int __Digits10,
   176          int __MinExp, int __MaxExp,
   177          int __MinExp10, int __MaxExp10,
   178          bool __IsIEC559,
   179          float_round_style __RoundStyle>
   180 class _Floating_limits : public _Numeric_limits_base<__number>
   181 {
   182 public:
   183 
   184 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   185   enum {
   186 # else
   187   static const int 
   188 # endif  
   189 
   190   digits = __Digits,
   191   digits10 = __Digits10,
   192 
   193   radix = (  FLT_RADIX /* 2 */ ),
   194   min_exponent = __MinExp, 
   195   max_exponent = __MaxExp,
   196   min_exponent10 = __MinExp10,
   197   max_exponent10 = __MaxExp10
   198 
   199 # if defined (_STLP_STATIC_CONST_INIT_BUG)
   200   ,  
   201   has_denorm = denorm_indeterminate,
   202   round_style = __RoundStyle,
   203 # else
   204   ;
   205   static const float_denorm_style has_denorm = denorm_indeterminate;
   206   static const float_round_style round_style = __RoundStyle;
   207   static const bool 
   208 # endif
   209 
   210   is_specialized = true,
   211   is_signed = true, 
   212 
   213 #if (!defined(_CRAY) || !defined(_CRAYIEEE))
   214    has_infinity     =  true,
   215    has_quiet_NaN    =  true,
   216    has_signaling_NaN=  true,
   217 #else
   218   has_infinity     =  false,
   219   has_quiet_NaN    =  false,
   220   has_signaling_NaN=  false,
   221 #endif
   222 
   223   has_denorm_loss  =  false,
   224   is_iec559      =  __IsIEC559,
   225   is_bounded     =  true,
   226   traps          =  true,
   227   tinyness_before=  false
   228 
   229 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   230   }
   231 # endif
   232   ;
   233 
   234 };
   235 
   236 // Class numeric_limits
   237 
   238 // The unspecialized class.
   239 
   240 template<class _Tp> 
   241 class numeric_limits : public _Numeric_limits_base<_Tp> {};
   242 
   243 // Specializations for all built-in integral types.
   244 
   245 #ifndef _STLP_NO_BOOL
   246 
   247 _STLP_TEMPLATE_NULL
   248 class   numeric_limits<bool>
   249   : public _Integer_limits<bool, false, true, 1, false>
   250 {};
   251 
   252 #endif /* _STLP_NO_BOOL */
   253 
   254 _STLP_TEMPLATE_NULL
   255 class   numeric_limits<char>
   256   : public _Integer_limits<char, CHAR_MIN, CHAR_MAX, -1, true>
   257 {};
   258 
   259 # ifndef _STLP_NO_SIGNED_BUILTINS
   260 _STLP_TEMPLATE_NULL
   261 class   numeric_limits<signed char>
   262   : public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX, -1, true>
   263 {};
   264 # endif
   265 
   266 _STLP_TEMPLATE_NULL
   267 class   numeric_limits<unsigned char>
   268   : public _Integer_limits<unsigned char, 0, UCHAR_MAX, -1, true>
   269 {};
   270 
   271 #ifdef __SYMBIAN32__
   272 #if !defined ( _STLP_NO_WCHAR_T )
   273 _STLP_TEMPLATE_NULL
   274 class   numeric_limits<wchar_t>
   275   : public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
   276 {};
   277 
   278 #endif
   279 #else
   280 #if !(defined ( _STLP_NO_WCHAR_T ) || defined (_STLP_WCHAR_T_IS_USHORT))
   281 
   282 _STLP_TEMPLATE_NULL
   283 class   numeric_limits<wchar_t>
   284   : public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
   285 {};
   286 #endif
   287 #endif
   288 
   289 _STLP_TEMPLATE_NULL
   290 class   numeric_limits<short>
   291   : public _Integer_limits<short, SHRT_MIN, SHRT_MAX, -1, true>
   292 {};
   293 
   294 _STLP_TEMPLATE_NULL
   295 class   numeric_limits<unsigned short>
   296   : public _Integer_limits<unsigned short, 0, USHRT_MAX, -1, true>
   297 {};
   298 
   299 # if defined (__xlC__) && (__xlC__ == 0x500)
   300 #  undef INT_MIN
   301 #  define INT_MIN -2147483648
   302 # endif
   303 
   304 
   305 _STLP_TEMPLATE_NULL
   306 class   numeric_limits<int>
   307   : public _Integer_limits<int, INT_MIN, INT_MAX, -1, true>
   308 {};
   309 
   310 _STLP_TEMPLATE_NULL
   311 class   numeric_limits<unsigned int>
   312   : public _Integer_limits<unsigned int, 0, UINT_MAX, -1, true>
   313 {};
   314 
   315 _STLP_TEMPLATE_NULL
   316 class   numeric_limits<long>
   317   : public _Integer_limits<long, LONG_MIN, LONG_MAX, -1, true>
   318 {};
   319 
   320 _STLP_TEMPLATE_NULL
   321 class   numeric_limits<unsigned long>
   322   : public _Integer_limits<unsigned long, 0, ULONG_MAX, -1, true>
   323 {};
   324 
   325 #ifdef _STLP_LONG_LONG
   326 
   327 # if defined (_STLP_MSVC) || defined (__BORLANDC__)
   328 
   329 #    define LONGLONG_MAX     0x7fffffffffffffffi64
   330 #    define LONGLONG_MIN     (-LONGLONG_MAX-1i64)
   331 #    define ULONGLONG_MAX    0xffffffffffffffffUi64
   332 
   333 # else
   334 
   335 #  ifndef   LONGLONG_MAX
   336 #    define LONGLONG_MAX     0x7fffffffffffffffLL
   337 #  endif
   338 #  ifndef   LONGLONG_MIN
   339 #    define LONGLONG_MIN     (-LONGLONG_MAX-1LL)
   340 #  endif
   341 #  ifndef   ULONGLONG_MAX
   342 #    define ULONGLONG_MAX    0xffffffffffffffffULL
   343 #  endif
   344 
   345 # endif
   346 
   347 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ <= 96)
   348 
   349 _STLP_TEMPLATE_NULL
   350 class   numeric_limits<_STLP_LONG_LONG>
   351   : public _Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
   352 {};
   353 
   354 _STLP_TEMPLATE_NULL
   355 class   numeric_limits<unsigned _STLP_LONG_LONG>
   356   : public _Integer_limits<unsigned _STLP_LONG_LONG, 0, ULONGLONG_MAX, -1, true>
   357 {};
   358 #else /* gcc 2.97 (after 2000-11-01), 2.98, 3.0 */
   359 /*
   360  newest gcc has new mangling scheme, that has problem
   361  with generating name [instantiated] of template specialization like
   362  _Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
   363                                   ~~~~~~~~~~~~  ~~~~~~~~~~~~
   364  Below is code that solve this problem.
   365    - ptr
   366  */
   367 _STLP_TEMPLATE_NULL
   368 class   numeric_limits<_STLP_LONG_LONG>
   369   : public _Numeric_limits_base<_STLP_LONG_LONG> 
   370 {
   371 public:
   372 
   373   static _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return LONGLONG_MIN; }
   374   static _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return LONGLONG_MAX; }
   375 
   376 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   377   enum {
   378 # else
   379   static const int 
   380 # endif  
   381   digits = ((int)((sizeof(_STLP_LONG_LONG) * (CHAR_BIT))) - 1),
   382   digits10 = (digits * 301UL) / 1000,
   383   radix = 2
   384 # if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
   385   ;
   386   static const bool
   387 # else
   388   ,
   389 # endif
   390   is_specialized = true,
   391   is_signed = true,
   392   is_integer = true,
   393   is_exact = true,
   394   is_bounded = true,
   395   is_modulo = true
   396 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   397   }
   398 # endif
   399   ;
   400 };
   401 
   402 _STLP_TEMPLATE_NULL
   403 class   numeric_limits<unsigned _STLP_LONG_LONG>
   404   : public _Numeric_limits_base<unsigned _STLP_LONG_LONG> 
   405 {
   406 public:
   407 
   408   static unsigned _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return 0ULL; }
   409   static unsigned _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return ULONGLONG_MAX; }
   410 
   411 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   412   enum {
   413 # else
   414   static const int 
   415 # endif  
   416   digits = ((int)((sizeof(unsigned _STLP_LONG_LONG) * (CHAR_BIT)))),
   417   digits10 = (digits * 301UL) / 1000,
   418   radix = 2
   419 # if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
   420   ;
   421   static const bool
   422 # else
   423   ,
   424 # endif
   425   is_specialized = true,
   426   is_signed = false,
   427   is_integer = true,
   428   is_exact = true,
   429   is_bounded = true,
   430   is_modulo = true
   431 # if defined ( _STLP_STATIC_CONST_INIT_BUG)
   432   }
   433 # endif
   434   ;
   435 };
   436 
   437 # endif /* __GNUC__ > 2000-11-01 */
   438 
   439 #endif /* _STLP_LONG_LONG */
   440 
   441 // Specializations for all built-in floating-point types.
   442 
   443 union _F_rep
   444 {
   445   unsigned short rep[2];
   446   float val;
   447 };
   448 union _D_rep
   449 {
   450   unsigned short rep[4];
   451   double val;
   452 };
   453 
   454 # ifndef _STLP_NO_LONG_DOUBLE
   455 union _L_rep
   456 {
   457   unsigned short rep[8];
   458   long double val;
   459 };
   460 # endif
   461 
   462 template <class __dummy>
   463 class _LimG 
   464 {
   465 public:  
   466   static const _F_rep _F_inf;
   467   static const _F_rep _F_qNaN;
   468   static const _F_rep _F_sNaN;
   469   static const _D_rep _D_inf;
   470   static const _D_rep _D_qNaN;
   471   static const _D_rep _D_sNaN;
   472   
   473 # ifndef _STLP_NO_LONG_DOUBLE
   474   static const _L_rep _L_inf;
   475   static const _L_rep _L_qNaN;
   476   static const _L_rep _L_sNaN;
   477 # endif
   478 };
   479 
   480 # if defined (_STLP_USE_TEMPLATE_EXPORT) 
   481 _STLP_EXPORT_TEMPLATE_CLASS _LimG<bool>;
   482 # endif
   483 
   484 _STLP_TEMPLATE_NULL class   numeric_limits<float>
   485   : public _Floating_limits<float, 
   486                             FLT_MANT_DIG,   // Binary digits of precision
   487                             FLT_DIG,        // Decimal digits of precision
   488                             FLT_MIN_EXP,    // Minimum exponent
   489                             FLT_MAX_EXP,    // Maximum exponent
   490                             FLT_MIN_10_EXP, // Minimum base 10 exponent
   491                             FLT_MAX_10_EXP, // Maximum base 10 exponent
   492                             true,           // conforms to iec559
   493                             round_to_nearest>
   494 {
   495 public:
   496   static float (_STLP_CALL min) () _STLP_NOTHROW { return FLT_MIN; }
   497   static float _STLP_CALL denorm_min() _STLP_NOTHROW { return FLT_MIN; }
   498   static float (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return FLT_MAX; }
   499   static float _STLP_CALL epsilon() _STLP_NOTHROW { return FLT_EPSILON; }
   500   static float _STLP_CALL round_error() _STLP_NOTHROW { return 0.5f; } // Units: ulps.
   501   static  float _STLP_CALL infinity() { return _LimG<bool>::_F_inf.val; }
   502   static  float _STLP_CALL quiet_NaN() { return _LimG<bool>::_F_qNaN.val; }
   503   static  float _STLP_CALL signaling_NaN() { return _LimG<bool>::_F_sNaN.val; }
   504 };
   505 
   506 _STLP_TEMPLATE_NULL class   numeric_limits<double>
   507   : public _Floating_limits<double, 
   508                             DBL_MANT_DIG,   // Binary digits of precision
   509                             DBL_DIG,        // Decimal digits of precision
   510                             DBL_MIN_EXP,    // Minimum exponent
   511                             DBL_MAX_EXP,    // Maximum exponent
   512                             DBL_MIN_10_EXP, // Minimum base 10 exponent
   513                             DBL_MAX_10_EXP, // Maximum base 10 exponent
   514                             true,           // conforms to iec559
   515                             round_to_nearest>
   516 {
   517 public:
   518   static double (_STLP_CALL min)() _STLP_NOTHROW { return DBL_MIN; }
   519   static double _STLP_CALL denorm_min() _STLP_NOTHROW { return DBL_MIN; }
   520   static double (_STLP_CALL max)() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return DBL_MAX; }
   521   static double _STLP_CALL epsilon() _STLP_NOTHROW { return DBL_EPSILON; }
   522   static double _STLP_CALL round_error() _STLP_NOTHROW { return 0.5; } // Units: ulps.
   523   static  double _STLP_CALL infinity() { return _LimG<bool>::_D_inf.val; }
   524   static  double _STLP_CALL quiet_NaN(){ return _LimG<bool>::_D_qNaN.val; }
   525   static  double _STLP_CALL signaling_NaN() { return _LimG<bool>::_D_sNaN.val; }
   526 };
   527 
   528 # ifndef _STLP_NO_LONG_DOUBLE
   529 
   530 _STLP_TEMPLATE_NULL 
   531 class   numeric_limits<long double>
   532   : public _Floating_limits<long double, 
   533                             LDBL_MANT_DIG,  // Binary digits of precision
   534                             LDBL_DIG,       // Decimal digits of precision
   535                             LDBL_MIN_EXP,   // Minimum exponent
   536                             LDBL_MAX_EXP,   // Maximum exponent
   537                             LDBL_MIN_10_EXP,// Minimum base 10 exponent
   538                             LDBL_MAX_10_EXP,// Maximum base 10 exponent
   539                             false,          // Doesn't conform to iec559
   540                             round_to_nearest>
   541 {
   542 public:
   543   static long double (_STLP_CALL min) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
   544   static long double _STLP_CALL denorm_min() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
   545   static long double (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MAX; }
   546   static long double _STLP_CALL epsilon() _STLP_NOTHROW { return LDBL_EPSILON; }
   547   static long double _STLP_CALL round_error() _STLP_NOTHROW { return 4; } // Units: ulps.
   548   static long double _STLP_CALL infinity() { return _LimG<bool>::_L_inf.val; } 
   549   static long double _STLP_CALL quiet_NaN() { return _LimG<bool>::_L_qNaN.val; }
   550   static long double _STLP_CALL signaling_NaN() { return _LimG<bool>::_L_sNaN.val; }
   551 };
   552 
   553 # endif
   554 
   555 // We write special values (Inf and NaN) as bit patterns and 
   556 // cast the the appropriate floating-point types. 
   557 _STLP_END_NAMESPACE
   558 
   559 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
   560 #  include <stl/_limits.c>
   561 # endif
   562 
   563 #endif
   564 
   565 // Local Variables:
   566 // mode:C++
   567 // End: