00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef BOOST_SGI_CPP_LIMITS
00040 #define BOOST_SGI_CPP_LIMITS
00041
00042 #include <climits>
00043 #include <cfloat>
00044 #include <sysc/packages/boost/config.hpp>
00045 #include <sysc/packages/boost/detail/endian.hpp>
00046
00047 #ifndef BOOST_NO_CWCHAR
00048 #include <cwchar>
00049 #endif
00050
00051 namespace std {
00052
00053 enum float_round_style {
00054 round_indeterminate = -1,
00055 round_toward_zero = 0,
00056 round_to_nearest = 1,
00057 round_toward_infinity = 2,
00058 round_toward_neg_infinity = 3
00059 };
00060
00061 enum float_denorm_style {
00062 denorm_indeterminate = -1,
00063 denorm_absent = 0,
00064 denorm_present = 1
00065 };
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
00081 # define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
00082 enum { __mem_name = __mem_value }
00083 #else
00084 # define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
00085 static const __mem_type __mem_name = __mem_value
00086 #endif
00087
00088
00089 template <class __number>
00090 class _Numeric_limits_base {
00091 public:
00092 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false);
00093
00094 static __number min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); }
00095 static __number max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); }
00096
00097 BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, 0);
00098 BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, 0);
00099
00100 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, false);
00101 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false);
00102 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, false);
00103
00104 BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 0);
00105
00106 static __number epsilon() throw() { return __number(); }
00107 static __number round_error() throw() { return __number(); }
00108
00109 BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, 0);
00110 BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0);
00111 BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, 0);
00112 BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0);
00113
00114 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, false);
00115 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, false);
00116 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false);
00117 BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
00118 has_denorm,
00119 denorm_absent);
00120 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
00121
00122 static __number infinity() throw() { return __number(); }
00123 static __number quiet_NaN() throw() { return __number(); }
00124 static __number signaling_NaN() throw() { return __number(); }
00125 static __number denorm_min() throw() { return __number(); }
00126
00127 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, false);
00128 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false);
00129 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, false);
00130
00131 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false);
00132 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
00133 BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style,
00134 round_style,
00135 round_toward_zero);
00136 };
00137
00138
00139
00140 template <class _Int,
00141 _Int __imin,
00142 _Int __imax,
00143 int __idigits = -1>
00144 class _Integer_limits : public _Numeric_limits_base<_Int>
00145 {
00146 public:
00147 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
00148
00149 static _Int min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imin; }
00150 static _Int max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imax; }
00151
00152 BOOST_STL_DECLARE_LIMITS_MEMBER(int,
00153 digits,
00154 (__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT)
00155 - (__imin == 0 ? 0 : 1)
00156 : __idigits);
00157 BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000);
00158
00159
00160 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, __imin != 0);
00161 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true);
00162 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, true);
00163 BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
00164
00165 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
00166 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, true);
00167 };
00168
00169 #if defined(BOOST_BIG_ENDIAN)
00170
00171 template<class Number, unsigned int Word>
00172 struct float_helper{
00173 static Number get_word() throw() {
00174
00175 const unsigned int _S_word[4] = { Word, 0, 0, 0 };
00176 return *reinterpret_cast<const Number*>(&_S_word);
00177 }
00178 };
00179
00180 #else
00181
00182 template<class Number, unsigned int Word>
00183 struct float_helper{
00184 static Number get_word() throw() {
00185
00186 const unsigned int _S_word[4] = { 0, 0, 0, Word };
00187 return *reinterpret_cast<const Number*>(
00188 reinterpret_cast<const char *>(&_S_word)+16-
00189 (sizeof(Number) == 12 ? 10 : sizeof(Number)));
00190 }
00191 };
00192
00193 #endif
00194
00195
00196 template <class __number,
00197 int __Digits, int __Digits10,
00198 int __MinExp, int __MaxExp,
00199 int __MinExp10, int __MaxExp10,
00200 unsigned int __InfinityWord,
00201 unsigned int __QNaNWord, unsigned int __SNaNWord,
00202 bool __IsIEC559,
00203 float_round_style __RoundStyle>
00204 class _Floating_limits : public _Numeric_limits_base<__number>
00205 {
00206 public:
00207 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
00208
00209 BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, __Digits);
00210 BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10);
00211
00212 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true);
00213
00214 BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
00215
00216 BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, __MinExp);
00217 BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, __MaxExp);
00218 BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10);
00219 BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10);
00220
00221 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, true);
00222 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, true);
00223 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true);
00224 BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
00225 has_denorm,
00226 denorm_indeterminate);
00227 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
00228
00229
00230 static __number infinity() throw() {
00231 return float_helper<__number, __InfinityWord>::get_word();
00232 }
00233 static __number quiet_NaN() throw() {
00234 return float_helper<__number,__QNaNWord>::get_word();
00235 }
00236 static __number signaling_NaN() throw() {
00237 return float_helper<__number,__SNaNWord>::get_word();
00238 }
00239
00240 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, __IsIEC559);
00241 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
00242 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false );
00243 BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
00244
00245 BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle);
00246 };
00247
00248
00249
00250
00251
00252 template<class T>
00253 class numeric_limits : public _Numeric_limits_base<T> {};
00254
00255
00256
00257 template<>
00258 class numeric_limits<bool>
00259 : public _Integer_limits<bool, false, true, 0>
00260 {};
00261
00262 template<>
00263 class numeric_limits<char>
00264 : public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
00265 {};
00266
00267 template<>
00268 class numeric_limits<signed char>
00269 : public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX>
00270 {};
00271
00272 template<>
00273 class numeric_limits<unsigned char>
00274 : public _Integer_limits<unsigned char, 0, UCHAR_MAX>
00275 {};
00276
00277 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
00278 template<>
00279 class numeric_limits<wchar_t>
00280 #if !defined(WCHAR_MAX) || !defined(WCHAR_MIN)
00281 #if defined(_WIN32) || defined(__CYGWIN__)
00282 : public _Integer_limits<wchar_t, 0, USHRT_MAX>
00283 #elif defined(__hppa)
00284
00285 : public _Integer_limits<wchar_t, 0, UINT_MAX>
00286 #else
00287
00288 : public _Integer_limits<wchar_t, INT_MIN, INT_MAX>
00289 #endif
00290 #else
00291
00292 : public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX>
00293 #endif
00294 {};
00295 #endif
00296
00297 template<>
00298 class numeric_limits<short>
00299 : public _Integer_limits<short, SHRT_MIN, SHRT_MAX>
00300 {};
00301
00302 template<>
00303 class numeric_limits<unsigned short>
00304 : public _Integer_limits<unsigned short, 0, USHRT_MAX>
00305 {};
00306
00307 template<>
00308 class numeric_limits<int>
00309 : public _Integer_limits<int, INT_MIN, INT_MAX>
00310 {};
00311
00312 template<>
00313 class numeric_limits<unsigned int>
00314 : public _Integer_limits<unsigned int, 0, UINT_MAX>
00315 {};
00316
00317 template<>
00318 class numeric_limits<long>
00319 : public _Integer_limits<long, LONG_MIN, LONG_MAX>
00320 {};
00321
00322 template<>
00323 class numeric_limits<unsigned long>
00324 : public _Integer_limits<unsigned long, 0, ULONG_MAX>
00325 {};
00326
00327 #ifdef __GNUC__
00328
00329
00330
00331
00332 #if !defined(LONGLONG_MAX) && !defined(ULONGLONG_MAX)
00333
00334 # define ULONGLONG_MAX 0xffffffffffffffffLLU
00335 # define LONGLONG_MAX 0x7fffffffffffffffLL
00336
00337 #endif
00338
00339 #if !defined(LONGLONG_MIN)
00340 # define LONGLONG_MIN (-LONGLONG_MAX - 1)
00341 #endif
00342
00343
00344 #if !defined(ULONGLONG_MIN)
00345 # define ULONGLONG_MIN 0
00346 #endif
00347
00348 #endif
00349
00350
00351
00352 template<> class numeric_limits<float>
00353 : public _Floating_limits<float,
00354 FLT_MANT_DIG,
00355 FLT_DIG,
00356 FLT_MIN_EXP,
00357 FLT_MAX_EXP,
00358 FLT_MIN_10_EXP,
00359 FLT_MAX_10_EXP,
00360 #if defined(BOOST_BIG_ENDIAN)
00361 0x7f80 << (sizeof(int)*CHAR_BIT-16),
00362 0x7f81 << (sizeof(int)*CHAR_BIT-16),
00363 0x7fc1 << (sizeof(int)*CHAR_BIT-16),
00364 #else
00365 0x7f800000u,
00366 0x7f810000u,
00367 0x7fc10000u,
00368 #endif
00369 true,
00370 round_to_nearest>
00371 {
00372 public:
00373 static float min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MIN; }
00374 static float denorm_min() throw() { return FLT_MIN; }
00375 static float max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MAX; }
00376 static float epsilon() throw() { return FLT_EPSILON; }
00377 static float round_error() throw() { return 0.5f; }
00378 };
00379
00380 template<> class numeric_limits<double>
00381 : public _Floating_limits<double,
00382 DBL_MANT_DIG,
00383 DBL_DIG,
00384 DBL_MIN_EXP,
00385 DBL_MAX_EXP,
00386 DBL_MIN_10_EXP,
00387 DBL_MAX_10_EXP,
00388 #if defined(BOOST_BIG_ENDIAN)
00389 0x7ff0 << (sizeof(int)*CHAR_BIT-16),
00390 0x7ff1 << (sizeof(int)*CHAR_BIT-16),
00391 0x7ff9 << (sizeof(int)*CHAR_BIT-16),
00392 #else
00393 0x7ff00000u,
00394 0x7ff10000u,
00395 0x7ff90000u,
00396 #endif
00397 true,
00398 round_to_nearest>
00399 {
00400 public:
00401 static double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MIN; }
00402 static double denorm_min() throw() { return DBL_MIN; }
00403 static double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MAX; }
00404 static double epsilon() throw() { return DBL_EPSILON; }
00405 static double round_error() throw() { return 0.5; }
00406 };
00407
00408 template<> class numeric_limits<long double>
00409 : public _Floating_limits<long double,
00410 LDBL_MANT_DIG,
00411 LDBL_DIG,
00412 LDBL_MIN_EXP,
00413 LDBL_MAX_EXP,
00414 LDBL_MIN_10_EXP,
00415 LDBL_MAX_10_EXP,
00416 #if defined(BOOST_BIG_ENDIAN)
00417 0x7ff0 << (sizeof(int)*CHAR_BIT-16),
00418 0x7ff1 << (sizeof(int)*CHAR_BIT-16),
00419 0x7ff9 << (sizeof(int)*CHAR_BIT-16),
00420 #else
00421 0x7fff8000u,
00422 0x7fffc000u,
00423 0x7fff9000u,
00424 #endif
00425 false,
00426 round_to_nearest>
00427 {
00428 public:
00429 static long double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MIN; }
00430 static long double denorm_min() throw() { return LDBL_MIN; }
00431 static long double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MAX; }
00432 static long double epsilon() throw() { return LDBL_EPSILON; }
00433 static long double round_error() throw() { return 4; }
00434 };
00435
00436 }
00437
00438 #endif
00439
00440
00441
00442
00443
00444
00445