sl@0: // Copyright 2001 John Maddock sl@0: // Distributed under the Boost Software License, Version 1.0. (See accompany- sl@0: // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: /* sl@0: * Copyright (c) 1997 sl@0: * Silicon Graphics Computer Systems, Inc. sl@0: * sl@0: * Permission to use, copy, modify, distribute and sell this software sl@0: * and its documentation for any purpose is hereby granted without fee, sl@0: * provided that the above copyright notice appear in all copies and sl@0: * that both that copyright notice and this permission notice appear sl@0: * in supporting documentation. Silicon Graphics makes no sl@0: * representations about the suitability of this software for any sl@0: * purpose. It is provided "as is" without express or implied warranty. sl@0: */ sl@0: sl@0: /* NOTE: This is not portable code. Parts of numeric_limits<> are sl@0: * inherently machine-dependent, and this file is written for the MIPS sl@0: * architecture and the SGI MIPSpro C++ compiler. Parts of it (in sl@0: * particular, some of the characteristics of floating-point types) sl@0: * are almost certainly incorrect for any other platform. sl@0: */ sl@0: sl@0: /* The above comment is almost certainly out of date. This file works sl@0: * on systems other than SGI MIPSpro C++ now. sl@0: */ sl@0: sl@0: /* sl@0: * Revision history: sl@0: * 21 Sep 2001: sl@0: * Only include if BOOST_NO_CWCHAR is defined. (Darin Adler) sl@0: * 10 Aug 2001: sl@0: * Added MIPS (big endian) to the big endian family. (Jens Maurer) sl@0: * 13 Apr 2001: sl@0: * Added powerpc to the big endian family. (Jeremy Siek) sl@0: * 5 Apr 2001: sl@0: * Added sparc (big endian) processor support (John Maddock). sl@0: * Initial sub: sl@0: * Modified by Jens Maurer for gcc 2.95 on x86. sl@0: */ sl@0: sl@0: #ifndef BOOST_SGI_CPP_LIMITS sl@0: #define BOOST_SGI_CPP_LIMITS sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifndef BOOST_NO_CWCHAR sl@0: #include // for WCHAR_MIN and WCHAR_MAX sl@0: #endif sl@0: sl@0: namespace std { sl@0: sl@0: enum float_round_style { sl@0: round_indeterminate = -1, sl@0: round_toward_zero = 0, sl@0: round_to_nearest = 1, sl@0: round_toward_infinity = 2, sl@0: round_toward_neg_infinity = 3 sl@0: }; sl@0: sl@0: enum float_denorm_style { sl@0: denorm_indeterminate = -1, sl@0: denorm_absent = 0, sl@0: denorm_present = 1 sl@0: }; sl@0: sl@0: // The C++ standard (section 18.2.1) requires that some of the members of sl@0: // numeric_limits be static const data members that are given constant- sl@0: // initializers within the class declaration. On compilers where the sl@0: // BOOST_NO_INCLASS_MEMBER_INITIALIZATION macro is defined, it is impossible to write sl@0: // a standard-conforming numeric_limits class. sl@0: // sl@0: // There are two possible workarounds: either initialize the data sl@0: // members outside the class, or change them from data members to sl@0: // enums. Neither workaround is satisfactory: the former makes it sl@0: // impossible to use the data members in constant-expressions, and the sl@0: // latter means they have the wrong type and that it is impossible to sl@0: // take their addresses. We choose the former workaround. sl@0: sl@0: #ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION sl@0: # define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \ sl@0: enum { __mem_name = __mem_value } sl@0: #else /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */ sl@0: # define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \ sl@0: static const __mem_type __mem_name = __mem_value sl@0: #endif /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */ sl@0: sl@0: // Base class for all specializations of numeric_limits. sl@0: template sl@0: class _Numeric_limits_base { sl@0: public: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false); sl@0: sl@0: static __number min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); } sl@0: static __number max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); } sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, 0); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, 0); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, false); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 0); sl@0: sl@0: static __number epsilon() throw() { return __number(); } sl@0: static __number round_error() throw() { return __number(); } sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, 0); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, 0); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style, sl@0: has_denorm, sl@0: denorm_absent); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false); sl@0: sl@0: static __number infinity() throw() { return __number(); } sl@0: static __number quiet_NaN() throw() { return __number(); } sl@0: static __number signaling_NaN() throw() { return __number(); } sl@0: static __number denorm_min() throw() { return __number(); } sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, false); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style, sl@0: round_style, sl@0: round_toward_zero); sl@0: }; sl@0: sl@0: // Base class for integers. sl@0: sl@0: template sl@0: class _Integer_limits : public _Numeric_limits_base<_Int> sl@0: { sl@0: public: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true); sl@0: sl@0: static _Int min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imin; } sl@0: static _Int max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imax; } sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, sl@0: digits, sl@0: (__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT) sl@0: - (__imin == 0 ? 0 : 1) sl@0: : __idigits); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000); sl@0: // log 2 = 0.301029995664... sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, __imin != 0); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, true); sl@0: }; sl@0: sl@0: #if defined(BOOST_BIG_ENDIAN) sl@0: sl@0: template sl@0: struct float_helper{ sl@0: static Number get_word() throw() { sl@0: // sizeof(long double) == 16 sl@0: const unsigned int _S_word[4] = { Word, 0, 0, 0 }; sl@0: return *reinterpret_cast(&_S_word); sl@0: } sl@0: }; sl@0: sl@0: #else sl@0: sl@0: template sl@0: struct float_helper{ sl@0: static Number get_word() throw() { sl@0: // sizeof(long double) == 12, but only 10 bytes significant sl@0: const unsigned int _S_word[4] = { 0, 0, 0, Word }; sl@0: return *reinterpret_cast( sl@0: reinterpret_cast(&_S_word)+16- sl@0: (sizeof(Number) == 12 ? 10 : sizeof(Number))); sl@0: } sl@0: }; sl@0: sl@0: #endif sl@0: sl@0: // Base class for floating-point numbers. sl@0: template sl@0: class _Floating_limits : public _Numeric_limits_base<__number> sl@0: { sl@0: public: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, __Digits); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, __MinExp); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, __MaxExp); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style, sl@0: has_denorm, sl@0: denorm_indeterminate); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false); sl@0: sl@0: sl@0: static __number infinity() throw() { sl@0: return float_helper<__number, __InfinityWord>::get_word(); sl@0: } sl@0: static __number quiet_NaN() throw() { sl@0: return float_helper<__number,__QNaNWord>::get_word(); sl@0: } sl@0: static __number signaling_NaN() throw() { sl@0: return float_helper<__number,__SNaNWord>::get_word(); sl@0: } sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, __IsIEC559); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false /* was: true */ ); sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false); sl@0: sl@0: BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle); sl@0: }; sl@0: sl@0: // Class numeric_limits sl@0: sl@0: // The unspecialized class. sl@0: sl@0: template sl@0: class numeric_limits : public _Numeric_limits_base {}; sl@0: sl@0: // Specializations for all built-in integral types. sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: #ifndef BOOST_NO_INTRINSIC_WCHAR_T sl@0: template<> sl@0: class numeric_limits sl@0: #if !defined(WCHAR_MAX) || !defined(WCHAR_MIN) sl@0: #if defined(_WIN32) || defined(__CYGWIN__) sl@0: : public _Integer_limits sl@0: #elif defined(__hppa) sl@0: // wchar_t has "unsigned int" as the underlying type sl@0: : public _Integer_limits sl@0: #else sl@0: // assume that wchar_t has "int" as the underlying type sl@0: : public _Integer_limits sl@0: #endif sl@0: #else sl@0: // we have WCHAR_MIN and WCHAR_MAX defined, so use it sl@0: : public _Integer_limits sl@0: #endif sl@0: {}; sl@0: #endif sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: template<> sl@0: class numeric_limits sl@0: : public _Integer_limits sl@0: {}; sl@0: sl@0: #ifdef __GNUC__ sl@0: sl@0: // Some compilers have long long, but don't define the sl@0: // LONGLONG_MIN and LONGLONG_MAX macros in limits.h. This sl@0: // assumes that long long is 64 bits. sl@0: #if !defined(LONGLONG_MAX) && !defined(ULONGLONG_MAX) sl@0: sl@0: # define ULONGLONG_MAX 0xffffffffffffffffLLU sl@0: # define LONGLONG_MAX 0x7fffffffffffffffLL sl@0: sl@0: #endif sl@0: sl@0: #if !defined(LONGLONG_MIN) sl@0: # define LONGLONG_MIN (-LONGLONG_MAX - 1) sl@0: #endif sl@0: sl@0: sl@0: #if !defined(ULONGLONG_MIN) sl@0: # define ULONGLONG_MIN 0 sl@0: #endif sl@0: sl@0: #endif /* __GNUC__ */ sl@0: sl@0: // Specializations for all built-in floating-point type. sl@0: sl@0: template<> class numeric_limits sl@0: : public _Floating_limits sl@0: { sl@0: public: sl@0: static float min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MIN; } sl@0: static float denorm_min() throw() { return FLT_MIN; } sl@0: static float max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MAX; } sl@0: static float epsilon() throw() { return FLT_EPSILON; } sl@0: static float round_error() throw() { return 0.5f; } // Units: ulps. sl@0: }; sl@0: sl@0: template<> class numeric_limits sl@0: : public _Floating_limits sl@0: { sl@0: public: sl@0: static double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MIN; } sl@0: static double denorm_min() throw() { return DBL_MIN; } sl@0: static double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MAX; } sl@0: static double epsilon() throw() { return DBL_EPSILON; } sl@0: static double round_error() throw() { return 0.5; } // Units: ulps. sl@0: }; sl@0: sl@0: template<> class numeric_limits sl@0: : public _Floating_limits sl@0: { sl@0: public: sl@0: static long double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MIN; } sl@0: static long double denorm_min() throw() { return LDBL_MIN; } sl@0: static long double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MAX; } sl@0: static long double epsilon() throw() { return LDBL_EPSILON; } sl@0: static long double round_error() throw() { return 4; } // Units: ulps. sl@0: }; sl@0: sl@0: } // namespace std sl@0: sl@0: #endif /* BOOST_SGI_CPP_LIMITS */ sl@0: sl@0: // Local Variables: sl@0: // mode:C++ sl@0: // End: sl@0: sl@0: sl@0: