123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- #ifndef BOOST_SGI_CPP_LIMITS
- #define BOOST_SGI_CPP_LIMITS
- #include <climits>
- #include <cfloat>
- #include <boost/config.hpp>
- #include <boost/detail/endian.hpp>
- #ifndef BOOST_NO_CWCHAR
- #include <cwchar>
- #endif
- namespace std {
- enum float_round_style {
- round_indeterminate = -1,
- round_toward_zero = 0,
- round_to_nearest = 1,
- round_toward_infinity = 2,
- round_toward_neg_infinity = 3
- };
- enum float_denorm_style {
- denorm_indeterminate = -1,
- denorm_absent = 0,
- denorm_present = 1
- };
- #ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
- # define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
- enum { __mem_name = __mem_value }
- #else
- # define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
- static const __mem_type __mem_name = __mem_value
- #endif
- template <class __number>
- class _Numeric_limits_base {
- public:
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false);
- static __number min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); }
- static __number max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); }
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 0);
- static __number epsilon() throw() { return __number(); }
- static __number round_error() throw() { return __number(); }
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
- has_denorm,
- denorm_absent);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
- static __number infinity() throw() { return __number(); }
- static __number quiet_NaN() throw() { return __number(); }
- static __number signaling_NaN() throw() { return __number(); }
- static __number denorm_min() throw() { return __number(); }
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style,
- round_style,
- round_toward_zero);
- };
- template <class _Int,
- _Int __imin,
- _Int __imax,
- int __idigits = -1>
- class _Integer_limits : public _Numeric_limits_base<_Int>
- {
- public:
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
- static _Int min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imin; }
- static _Int max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imax; }
- BOOST_STL_DECLARE_LIMITS_MEMBER(int,
- digits,
- (__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT)
- - (__imin == 0 ? 0 : 1)
- : __idigits);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000);
-
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, __imin != 0);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, true);
- };
- #if defined(BOOST_BIG_ENDIAN)
- template<class Number, unsigned int Word>
- struct float_helper{
- static Number get_word() throw() {
-
- const unsigned int _S_word[4] = { Word, 0, 0, 0 };
- return *reinterpret_cast<const Number*>(&_S_word);
- }
- };
- #else
- template<class Number, unsigned int Word>
- struct float_helper{
- static Number get_word() throw() {
-
- const unsigned int _S_word[4] = { 0, 0, 0, Word };
- return *reinterpret_cast<const Number*>(
- reinterpret_cast<const char *>(&_S_word)+16-
- (sizeof(Number) == 12 ? 10 : sizeof(Number)));
- }
- };
- #endif
- template <class __number,
- int __Digits, int __Digits10,
- int __MinExp, int __MaxExp,
- int __MinExp10, int __MaxExp10,
- unsigned int __InfinityWord,
- unsigned int __QNaNWord, unsigned int __SNaNWord,
- bool __IsIEC559,
- float_round_style __RoundStyle>
- class _Floating_limits : public _Numeric_limits_base<__number>
- {
- public:
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, __Digits);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, __MinExp);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, __MaxExp);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10);
- BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
- has_denorm,
- denorm_indeterminate);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
-
- static __number infinity() throw() {
- return float_helper<__number, __InfinityWord>::get_word();
- }
- static __number quiet_NaN() throw() {
- return float_helper<__number,__QNaNWord>::get_word();
- }
- static __number signaling_NaN() throw() {
- return float_helper<__number,__SNaNWord>::get_word();
- }
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, __IsIEC559);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false );
- BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
- BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle);
- };
- template<class T>
- class numeric_limits : public _Numeric_limits_base<T> {};
- template<>
- class numeric_limits<bool>
- : public _Integer_limits<bool, false, true, 0>
- {};
- template<>
- class numeric_limits<char>
- : public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
- {};
- template<>
- class numeric_limits<signed char>
- : public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX>
- {};
- template<>
- class numeric_limits<unsigned char>
- : public _Integer_limits<unsigned char, 0, UCHAR_MAX>
- {};
- #ifndef BOOST_NO_INTRINSIC_WCHAR_T
- template<>
- class numeric_limits<wchar_t>
- #if !defined(WCHAR_MAX) || !defined(WCHAR_MIN)
- #if defined(_WIN32) || defined(__CYGWIN__)
- : public _Integer_limits<wchar_t, 0, USHRT_MAX>
- #elif defined(__hppa)
- : public _Integer_limits<wchar_t, 0, UINT_MAX>
- #else
- : public _Integer_limits<wchar_t, INT_MIN, INT_MAX>
- #endif
- #else
- : public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX>
- #endif
- {};
- #endif
- template<>
- class numeric_limits<short>
- : public _Integer_limits<short, SHRT_MIN, SHRT_MAX>
- {};
- template<>
- class numeric_limits<unsigned short>
- : public _Integer_limits<unsigned short, 0, USHRT_MAX>
- {};
- template<>
- class numeric_limits<int>
- : public _Integer_limits<int, INT_MIN, INT_MAX>
- {};
- template<>
- class numeric_limits<unsigned int>
- : public _Integer_limits<unsigned int, 0, UINT_MAX>
- {};
- template<>
- class numeric_limits<long>
- : public _Integer_limits<long, LONG_MIN, LONG_MAX>
- {};
- template<>
- class numeric_limits<unsigned long>
- : public _Integer_limits<unsigned long, 0, ULONG_MAX>
- {};
- #ifdef __GNUC__
- #if !defined(LONGLONG_MAX) && !defined(ULONGLONG_MAX)
- # define ULONGLONG_MAX 0xffffffffffffffffLLU
- # define LONGLONG_MAX 0x7fffffffffffffffLL
- #endif
- #if !defined(LONGLONG_MIN)
- # define LONGLONG_MIN (-LONGLONG_MAX - 1)
- #endif
- #if !defined(ULONGLONG_MIN)
- # define ULONGLONG_MIN 0
- #endif
- #endif
- template<> class numeric_limits<float>
- : public _Floating_limits<float,
- FLT_MANT_DIG,
- FLT_DIG,
- FLT_MIN_EXP,
- FLT_MAX_EXP,
- FLT_MIN_10_EXP,
- FLT_MAX_10_EXP,
- #if defined(BOOST_BIG_ENDIAN)
- 0x7f80 << (sizeof(int)*CHAR_BIT-16),
- 0x7f81 << (sizeof(int)*CHAR_BIT-16),
- 0x7fc1 << (sizeof(int)*CHAR_BIT-16),
- #else
- 0x7f800000u,
- 0x7f810000u,
- 0x7fc10000u,
- #endif
- true,
- round_to_nearest>
- {
- public:
- static float min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MIN; }
- static float denorm_min() throw() { return FLT_MIN; }
- static float max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MAX; }
- static float epsilon() throw() { return FLT_EPSILON; }
- static float round_error() throw() { return 0.5f; }
- };
- template<> class numeric_limits<double>
- : public _Floating_limits<double,
- DBL_MANT_DIG,
- DBL_DIG,
- DBL_MIN_EXP,
- DBL_MAX_EXP,
- DBL_MIN_10_EXP,
- DBL_MAX_10_EXP,
- #if defined(BOOST_BIG_ENDIAN)
- 0x7ff0 << (sizeof(int)*CHAR_BIT-16),
- 0x7ff1 << (sizeof(int)*CHAR_BIT-16),
- 0x7ff9 << (sizeof(int)*CHAR_BIT-16),
- #else
- 0x7ff00000u,
- 0x7ff10000u,
- 0x7ff90000u,
- #endif
- true,
- round_to_nearest>
- {
- public:
- static double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MIN; }
- static double denorm_min() throw() { return DBL_MIN; }
- static double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MAX; }
- static double epsilon() throw() { return DBL_EPSILON; }
- static double round_error() throw() { return 0.5; }
- };
- template<> class numeric_limits<long double>
- : public _Floating_limits<long double,
- LDBL_MANT_DIG,
- LDBL_DIG,
- LDBL_MIN_EXP,
- LDBL_MAX_EXP,
- LDBL_MIN_10_EXP,
- LDBL_MAX_10_EXP,
- #if defined(BOOST_BIG_ENDIAN)
- 0x7ff0 << (sizeof(int)*CHAR_BIT-16),
- 0x7ff1 << (sizeof(int)*CHAR_BIT-16),
- 0x7ff9 << (sizeof(int)*CHAR_BIT-16),
- #else
- 0x7fff8000u,
- 0x7fffc000u,
- 0x7fff9000u,
- #endif
- false,
- round_to_nearest>
- {
- public:
- static long double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MIN; }
- static long double denorm_min() throw() { return LDBL_MIN; }
- static long double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MAX; }
- static long double epsilon() throw() { return LDBL_EPSILON; }
- static long double round_error() throw() { return 4; }
- };
- }
- #endif
|