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