1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/detail/limits.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,449 @@
1.4 +// Copyright 2001 John Maddock
1.5 +// Distributed under the Boost Software License, Version 1.0. (See accompany-
1.6 +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.7 +
1.8 +/*
1.9 + * Copyright (c) 1997
1.10 + * Silicon Graphics Computer Systems, Inc.
1.11 + *
1.12 + * Permission to use, copy, modify, distribute and sell this software
1.13 + * and its documentation for any purpose is hereby granted without fee,
1.14 + * provided that the above copyright notice appear in all copies and
1.15 + * that both that copyright notice and this permission notice appear
1.16 + * in supporting documentation. Silicon Graphics makes no
1.17 + * representations about the suitability of this software for any
1.18 + * purpose. It is provided "as is" without express or implied warranty.
1.19 + */
1.20 +
1.21 +/* NOTE: This is not portable code. Parts of numeric_limits<> are
1.22 + * inherently machine-dependent, and this file is written for the MIPS
1.23 + * architecture and the SGI MIPSpro C++ compiler. Parts of it (in
1.24 + * particular, some of the characteristics of floating-point types)
1.25 + * are almost certainly incorrect for any other platform.
1.26 + */
1.27 +
1.28 +/* The above comment is almost certainly out of date. This file works
1.29 + * on systems other than SGI MIPSpro C++ now.
1.30 + */
1.31 +
1.32 +/*
1.33 + * Revision history:
1.34 + * 21 Sep 2001:
1.35 + * Only include <cwchar> if BOOST_NO_CWCHAR is defined. (Darin Adler)
1.36 + * 10 Aug 2001:
1.37 + * Added MIPS (big endian) to the big endian family. (Jens Maurer)
1.38 + * 13 Apr 2001:
1.39 + * Added powerpc to the big endian family. (Jeremy Siek)
1.40 + * 5 Apr 2001:
1.41 + * Added sparc (big endian) processor support (John Maddock).
1.42 + * Initial sub:
1.43 + * Modified by Jens Maurer for gcc 2.95 on x86.
1.44 + */
1.45 +
1.46 +#ifndef BOOST_SGI_CPP_LIMITS
1.47 +#define BOOST_SGI_CPP_LIMITS
1.48 +
1.49 +#include <climits>
1.50 +#include <cfloat>
1.51 +#include <boost/config.hpp>
1.52 +#include <boost/detail/endian.hpp>
1.53 +
1.54 +#ifndef BOOST_NO_CWCHAR
1.55 +#include <cwchar> // for WCHAR_MIN and WCHAR_MAX
1.56 +#endif
1.57 +
1.58 +namespace std {
1.59 +
1.60 +enum float_round_style {
1.61 + round_indeterminate = -1,
1.62 + round_toward_zero = 0,
1.63 + round_to_nearest = 1,
1.64 + round_toward_infinity = 2,
1.65 + round_toward_neg_infinity = 3
1.66 +};
1.67 +
1.68 +enum float_denorm_style {
1.69 + denorm_indeterminate = -1,
1.70 + denorm_absent = 0,
1.71 + denorm_present = 1
1.72 +};
1.73 +
1.74 +// The C++ standard (section 18.2.1) requires that some of the members of
1.75 +// numeric_limits be static const data members that are given constant-
1.76 +// initializers within the class declaration. On compilers where the
1.77 +// BOOST_NO_INCLASS_MEMBER_INITIALIZATION macro is defined, it is impossible to write
1.78 +// a standard-conforming numeric_limits class.
1.79 +//
1.80 +// There are two possible workarounds: either initialize the data
1.81 +// members outside the class, or change them from data members to
1.82 +// enums. Neither workaround is satisfactory: the former makes it
1.83 +// impossible to use the data members in constant-expressions, and the
1.84 +// latter means they have the wrong type and that it is impossible to
1.85 +// take their addresses. We choose the former workaround.
1.86 +
1.87 +#ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
1.88 +# define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
1.89 + enum { __mem_name = __mem_value }
1.90 +#else /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */
1.91 +# define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
1.92 + static const __mem_type __mem_name = __mem_value
1.93 +#endif /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */
1.94 +
1.95 +// Base class for all specializations of numeric_limits.
1.96 +template <class __number>
1.97 +class _Numeric_limits_base {
1.98 +public:
1.99 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false);
1.100 +
1.101 + static __number min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); }
1.102 + static __number max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); }
1.103 +
1.104 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, 0);
1.105 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, 0);
1.106 +
1.107 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, false);
1.108 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false);
1.109 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, false);
1.110 +
1.111 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 0);
1.112 +
1.113 + static __number epsilon() throw() { return __number(); }
1.114 + static __number round_error() throw() { return __number(); }
1.115 +
1.116 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, 0);
1.117 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0);
1.118 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, 0);
1.119 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0);
1.120 +
1.121 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, false);
1.122 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, false);
1.123 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false);
1.124 + BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
1.125 + has_denorm,
1.126 + denorm_absent);
1.127 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
1.128 +
1.129 + static __number infinity() throw() { return __number(); }
1.130 + static __number quiet_NaN() throw() { return __number(); }
1.131 + static __number signaling_NaN() throw() { return __number(); }
1.132 + static __number denorm_min() throw() { return __number(); }
1.133 +
1.134 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, false);
1.135 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false);
1.136 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, false);
1.137 +
1.138 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false);
1.139 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
1.140 + BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style,
1.141 + round_style,
1.142 + round_toward_zero);
1.143 +};
1.144 +
1.145 +// Base class for integers.
1.146 +
1.147 +template <class _Int,
1.148 + _Int __imin,
1.149 + _Int __imax,
1.150 + int __idigits = -1>
1.151 +class _Integer_limits : public _Numeric_limits_base<_Int>
1.152 +{
1.153 +public:
1.154 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
1.155 +
1.156 + static _Int min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imin; }
1.157 + static _Int max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imax; }
1.158 +
1.159 + BOOST_STL_DECLARE_LIMITS_MEMBER(int,
1.160 + digits,
1.161 + (__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT)
1.162 + - (__imin == 0 ? 0 : 1)
1.163 + : __idigits);
1.164 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000);
1.165 + // log 2 = 0.301029995664...
1.166 +
1.167 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, __imin != 0);
1.168 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true);
1.169 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, true);
1.170 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
1.171 +
1.172 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
1.173 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, true);
1.174 +};
1.175 +
1.176 +#if defined(BOOST_BIG_ENDIAN)
1.177 +
1.178 + template<class Number, unsigned int Word>
1.179 + struct float_helper{
1.180 + static Number get_word() throw() {
1.181 + // sizeof(long double) == 16
1.182 + const unsigned int _S_word[4] = { Word, 0, 0, 0 };
1.183 + return *reinterpret_cast<const Number*>(&_S_word);
1.184 + }
1.185 +};
1.186 +
1.187 +#else
1.188 +
1.189 + template<class Number, unsigned int Word>
1.190 + struct float_helper{
1.191 + static Number get_word() throw() {
1.192 + // sizeof(long double) == 12, but only 10 bytes significant
1.193 + const unsigned int _S_word[4] = { 0, 0, 0, Word };
1.194 + return *reinterpret_cast<const Number*>(
1.195 + reinterpret_cast<const char *>(&_S_word)+16-
1.196 + (sizeof(Number) == 12 ? 10 : sizeof(Number)));
1.197 + }
1.198 +};
1.199 +
1.200 +#endif
1.201 +
1.202 +// Base class for floating-point numbers.
1.203 +template <class __number,
1.204 + int __Digits, int __Digits10,
1.205 + int __MinExp, int __MaxExp,
1.206 + int __MinExp10, int __MaxExp10,
1.207 + unsigned int __InfinityWord,
1.208 + unsigned int __QNaNWord, unsigned int __SNaNWord,
1.209 + bool __IsIEC559,
1.210 + float_round_style __RoundStyle>
1.211 +class _Floating_limits : public _Numeric_limits_base<__number>
1.212 +{
1.213 +public:
1.214 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
1.215 +
1.216 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, __Digits);
1.217 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10);
1.218 +
1.219 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true);
1.220 +
1.221 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
1.222 +
1.223 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, __MinExp);
1.224 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, __MaxExp);
1.225 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10);
1.226 + BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10);
1.227 +
1.228 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, true);
1.229 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, true);
1.230 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true);
1.231 + BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
1.232 + has_denorm,
1.233 + denorm_indeterminate);
1.234 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
1.235 +
1.236 +
1.237 + static __number infinity() throw() {
1.238 + return float_helper<__number, __InfinityWord>::get_word();
1.239 + }
1.240 + static __number quiet_NaN() throw() {
1.241 + return float_helper<__number,__QNaNWord>::get_word();
1.242 + }
1.243 + static __number signaling_NaN() throw() {
1.244 + return float_helper<__number,__SNaNWord>::get_word();
1.245 + }
1.246 +
1.247 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, __IsIEC559);
1.248 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
1.249 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false /* was: true */ );
1.250 + BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
1.251 +
1.252 + BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle);
1.253 +};
1.254 +
1.255 +// Class numeric_limits
1.256 +
1.257 +// The unspecialized class.
1.258 +
1.259 +template<class T>
1.260 +class numeric_limits : public _Numeric_limits_base<T> {};
1.261 +
1.262 +// Specializations for all built-in integral types.
1.263 +
1.264 +template<>
1.265 +class numeric_limits<bool>
1.266 + : public _Integer_limits<bool, false, true, 0>
1.267 +{};
1.268 +
1.269 +template<>
1.270 +class numeric_limits<char>
1.271 + : public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
1.272 +{};
1.273 +
1.274 +template<>
1.275 +class numeric_limits<signed char>
1.276 + : public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX>
1.277 +{};
1.278 +
1.279 +template<>
1.280 +class numeric_limits<unsigned char>
1.281 + : public _Integer_limits<unsigned char, 0, UCHAR_MAX>
1.282 +{};
1.283 +
1.284 +#ifndef BOOST_NO_INTRINSIC_WCHAR_T
1.285 +template<>
1.286 +class numeric_limits<wchar_t>
1.287 +#if !defined(WCHAR_MAX) || !defined(WCHAR_MIN)
1.288 +#if defined(_WIN32) || defined(__CYGWIN__)
1.289 + : public _Integer_limits<wchar_t, 0, USHRT_MAX>
1.290 +#elif defined(__hppa)
1.291 +// wchar_t has "unsigned int" as the underlying type
1.292 + : public _Integer_limits<wchar_t, 0, UINT_MAX>
1.293 +#else
1.294 +// assume that wchar_t has "int" as the underlying type
1.295 + : public _Integer_limits<wchar_t, INT_MIN, INT_MAX>
1.296 +#endif
1.297 +#else
1.298 +// we have WCHAR_MIN and WCHAR_MAX defined, so use it
1.299 + : public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX>
1.300 +#endif
1.301 +{};
1.302 +#endif
1.303 +
1.304 +template<>
1.305 +class numeric_limits<short>
1.306 + : public _Integer_limits<short, SHRT_MIN, SHRT_MAX>
1.307 +{};
1.308 +
1.309 +template<>
1.310 +class numeric_limits<unsigned short>
1.311 + : public _Integer_limits<unsigned short, 0, USHRT_MAX>
1.312 +{};
1.313 +
1.314 +template<>
1.315 +class numeric_limits<int>
1.316 + : public _Integer_limits<int, INT_MIN, INT_MAX>
1.317 +{};
1.318 +
1.319 +template<>
1.320 +class numeric_limits<unsigned int>
1.321 + : public _Integer_limits<unsigned int, 0, UINT_MAX>
1.322 +{};
1.323 +
1.324 +template<>
1.325 +class numeric_limits<long>
1.326 + : public _Integer_limits<long, LONG_MIN, LONG_MAX>
1.327 +{};
1.328 +
1.329 +template<>
1.330 +class numeric_limits<unsigned long>
1.331 + : public _Integer_limits<unsigned long, 0, ULONG_MAX>
1.332 +{};
1.333 +
1.334 +#ifdef __GNUC__
1.335 +
1.336 +// Some compilers have long long, but don't define the
1.337 +// LONGLONG_MIN and LONGLONG_MAX macros in limits.h. This
1.338 +// assumes that long long is 64 bits.
1.339 +#if !defined(LONGLONG_MAX) && !defined(ULONGLONG_MAX)
1.340 +
1.341 +# define ULONGLONG_MAX 0xffffffffffffffffLLU
1.342 +# define LONGLONG_MAX 0x7fffffffffffffffLL
1.343 +
1.344 +#endif
1.345 +
1.346 +#if !defined(LONGLONG_MIN)
1.347 +# define LONGLONG_MIN (-LONGLONG_MAX - 1)
1.348 +#endif
1.349 +
1.350 +
1.351 +#if !defined(ULONGLONG_MIN)
1.352 +# define ULONGLONG_MIN 0
1.353 +#endif
1.354 +
1.355 +#endif /* __GNUC__ */
1.356 +
1.357 +// Specializations for all built-in floating-point type.
1.358 +
1.359 +template<> class numeric_limits<float>
1.360 + : public _Floating_limits<float,
1.361 + FLT_MANT_DIG, // Binary digits of precision
1.362 + FLT_DIG, // Decimal digits of precision
1.363 + FLT_MIN_EXP, // Minimum exponent
1.364 + FLT_MAX_EXP, // Maximum exponent
1.365 + FLT_MIN_10_EXP, // Minimum base 10 exponent
1.366 + FLT_MAX_10_EXP, // Maximum base 10 exponent
1.367 +#if defined(BOOST_BIG_ENDIAN)
1.368 + 0x7f80 << (sizeof(int)*CHAR_BIT-16), // Last word of +infinity
1.369 + 0x7f81 << (sizeof(int)*CHAR_BIT-16), // Last word of quiet NaN
1.370 + 0x7fc1 << (sizeof(int)*CHAR_BIT-16), // Last word of signaling NaN
1.371 +#else
1.372 + 0x7f800000u, // Last word of +infinity
1.373 + 0x7f810000u, // Last word of quiet NaN
1.374 + 0x7fc10000u, // Last word of signaling NaN
1.375 +#endif
1.376 + true, // conforms to iec559
1.377 + round_to_nearest>
1.378 +{
1.379 +public:
1.380 + static float min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MIN; }
1.381 + static float denorm_min() throw() { return FLT_MIN; }
1.382 + static float max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MAX; }
1.383 + static float epsilon() throw() { return FLT_EPSILON; }
1.384 + static float round_error() throw() { return 0.5f; } // Units: ulps.
1.385 +};
1.386 +
1.387 +template<> class numeric_limits<double>
1.388 + : public _Floating_limits<double,
1.389 + DBL_MANT_DIG, // Binary digits of precision
1.390 + DBL_DIG, // Decimal digits of precision
1.391 + DBL_MIN_EXP, // Minimum exponent
1.392 + DBL_MAX_EXP, // Maximum exponent
1.393 + DBL_MIN_10_EXP, // Minimum base 10 exponent
1.394 + DBL_MAX_10_EXP, // Maximum base 10 exponent
1.395 +#if defined(BOOST_BIG_ENDIAN)
1.396 + 0x7ff0 << (sizeof(int)*CHAR_BIT-16), // Last word of +infinity
1.397 + 0x7ff1 << (sizeof(int)*CHAR_BIT-16), // Last word of quiet NaN
1.398 + 0x7ff9 << (sizeof(int)*CHAR_BIT-16), // Last word of signaling NaN
1.399 +#else
1.400 + 0x7ff00000u, // Last word of +infinity
1.401 + 0x7ff10000u, // Last word of quiet NaN
1.402 + 0x7ff90000u, // Last word of signaling NaN
1.403 +#endif
1.404 + true, // conforms to iec559
1.405 + round_to_nearest>
1.406 +{
1.407 +public:
1.408 + static double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MIN; }
1.409 + static double denorm_min() throw() { return DBL_MIN; }
1.410 + static double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MAX; }
1.411 + static double epsilon() throw() { return DBL_EPSILON; }
1.412 + static double round_error() throw() { return 0.5; } // Units: ulps.
1.413 +};
1.414 +
1.415 +template<> class numeric_limits<long double>
1.416 + : public _Floating_limits<long double,
1.417 + LDBL_MANT_DIG, // Binary digits of precision
1.418 + LDBL_DIG, // Decimal digits of precision
1.419 + LDBL_MIN_EXP, // Minimum exponent
1.420 + LDBL_MAX_EXP, // Maximum exponent
1.421 + LDBL_MIN_10_EXP,// Minimum base 10 exponent
1.422 + LDBL_MAX_10_EXP,// Maximum base 10 exponent
1.423 +#if defined(BOOST_BIG_ENDIAN)
1.424 + 0x7ff0 << (sizeof(int)*CHAR_BIT-16), // Last word of +infinity
1.425 + 0x7ff1 << (sizeof(int)*CHAR_BIT-16), // Last word of quiet NaN
1.426 + 0x7ff9 << (sizeof(int)*CHAR_BIT-16), // Last word of signaling NaN
1.427 +#else
1.428 + 0x7fff8000u, // Last word of +infinity
1.429 + 0x7fffc000u, // Last word of quiet NaN
1.430 + 0x7fff9000u, // Last word of signaling NaN
1.431 +#endif
1.432 + false, // Doesn't conform to iec559
1.433 + round_to_nearest>
1.434 +{
1.435 +public:
1.436 + static long double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MIN; }
1.437 + static long double denorm_min() throw() { return LDBL_MIN; }
1.438 + static long double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MAX; }
1.439 + static long double epsilon() throw() { return LDBL_EPSILON; }
1.440 + static long double round_error() throw() { return 4; } // Units: ulps.
1.441 +};
1.442 +
1.443 +} // namespace std
1.444 +
1.445 +#endif /* BOOST_SGI_CPP_LIMITS */
1.446 +
1.447 +// Local Variables:
1.448 +// mode:C++
1.449 +// End:
1.450 +
1.451 +
1.452 +