1 | |
2 | // (C) Copyright John maddock 1999. |
3 | // (C) Copyright David Abrahams 2002. Distributed under the Boost |
4 | // Software License, Version 1.0. (See accompanying file |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | // |
7 | // use this header as a workaround for missing <limits> |
8 | |
9 | // See http://www.boost.org/libs/compatibility/index.html for documentation. |
10 | |
11 | #ifndef BOOST_LIMITS |
12 | #define BOOST_LIMITS |
13 | |
14 | #include <boost/config.hpp> |
15 | |
16 | #ifdef BOOST_NO_LIMITS |
17 | # error "There is no std::numeric_limits suppport available." |
18 | #else |
19 | # include <limits> |
20 | #endif |
21 | |
22 | #if (defined(BOOST_HAS_LONG_LONG) && defined(BOOST_NO_LONG_LONG_NUMERIC_LIMITS)) \ |
23 | || (defined(BOOST_HAS_MS_INT64) && defined(BOOST_NO_MS_INT64_NUMERIC_LIMITS)) |
24 | // Add missing specializations for numeric_limits: |
25 | #ifdef BOOST_HAS_MS_INT64 |
26 | # define BOOST_LLT __int64 |
27 | # define BOOST_ULLT unsigned __int64 |
28 | #else |
29 | # define BOOST_LLT ::boost::long_long_type |
30 | # define BOOST_ULLT ::boost::ulong_long_type |
31 | #endif |
32 | |
33 | #include <climits> // for CHAR_BIT |
34 | |
35 | namespace std |
36 | { |
37 | template<> |
38 | class numeric_limits<BOOST_LLT> |
39 | { |
40 | public: |
41 | |
42 | BOOST_STATIC_CONSTANT(bool, is_specialized = true); |
43 | #ifdef BOOST_HAS_MS_INT64 |
44 | static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0x8000000000000000i64; } |
45 | static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0x7FFFFFFFFFFFFFFFi64; } |
46 | #elif defined(LLONG_MAX) |
47 | static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LLONG_MIN; } |
48 | static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LLONG_MAX; } |
49 | #elif defined(LONGLONG_MAX) |
50 | static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LONGLONG_MIN; } |
51 | static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LONGLONG_MAX; } |
52 | #else |
53 | static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 1LL << (sizeof(BOOST_LLT) * CHAR_BIT - 1); } |
54 | static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ~(min)(); } |
55 | #endif |
56 | BOOST_STATIC_CONSTANT(int, digits = sizeof(BOOST_LLT) * CHAR_BIT -1); |
57 | BOOST_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BOOST_LLT) - 1) * 301L / 1000); |
58 | BOOST_STATIC_CONSTANT(bool, is_signed = true); |
59 | BOOST_STATIC_CONSTANT(bool, is_integer = true); |
60 | BOOST_STATIC_CONSTANT(bool, is_exact = true); |
61 | BOOST_STATIC_CONSTANT(int, radix = 2); |
62 | static BOOST_LLT epsilon() throw() { return 0; }; |
63 | static BOOST_LLT round_error() throw() { return 0; }; |
64 | |
65 | BOOST_STATIC_CONSTANT(int, min_exponent = 0); |
66 | BOOST_STATIC_CONSTANT(int, min_exponent10 = 0); |
67 | BOOST_STATIC_CONSTANT(int, max_exponent = 0); |
68 | BOOST_STATIC_CONSTANT(int, max_exponent10 = 0); |
69 | |
70 | BOOST_STATIC_CONSTANT(bool, has_infinity = false); |
71 | BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = false); |
72 | BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = false); |
73 | BOOST_STATIC_CONSTANT(bool, has_denorm = false); |
74 | BOOST_STATIC_CONSTANT(bool, has_denorm_loss = false); |
75 | static BOOST_LLT infinity() throw() { return 0; }; |
76 | static BOOST_LLT quiet_NaN() throw() { return 0; }; |
77 | static BOOST_LLT signaling_NaN() throw() { return 0; }; |
78 | static BOOST_LLT denorm_min() throw() { return 0; }; |
79 | |
80 | BOOST_STATIC_CONSTANT(bool, is_iec559 = false); |
81 | BOOST_STATIC_CONSTANT(bool, is_bounded = true); |
82 | BOOST_STATIC_CONSTANT(bool, is_modulo = true); |
83 | |
84 | BOOST_STATIC_CONSTANT(bool, traps = false); |
85 | BOOST_STATIC_CONSTANT(bool, tinyness_before = false); |
86 | BOOST_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero); |
87 | |
88 | }; |
89 | |
90 | template<> |
91 | class numeric_limits<BOOST_ULLT> |
92 | { |
93 | public: |
94 | |
95 | BOOST_STATIC_CONSTANT(bool, is_specialized = true); |
96 | #ifdef BOOST_HAS_MS_INT64 |
97 | static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0ui64; } |
98 | static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0xFFFFFFFFFFFFFFFFui64; } |
99 | #elif defined(ULLONG_MAX) && defined(ULLONG_MIN) |
100 | static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MIN; } |
101 | static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MAX; } |
102 | #elif defined(ULONGLONG_MAX) && defined(ULONGLONG_MIN) |
103 | static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MIN; } |
104 | static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MAX; } |
105 | #else |
106 | static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0uLL; } |
107 | static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ~0uLL; } |
108 | #endif |
109 | BOOST_STATIC_CONSTANT(int, digits = sizeof(BOOST_LLT) * CHAR_BIT); |
110 | BOOST_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BOOST_LLT)) * 301L / 1000); |
111 | BOOST_STATIC_CONSTANT(bool, is_signed = false); |
112 | BOOST_STATIC_CONSTANT(bool, is_integer = true); |
113 | BOOST_STATIC_CONSTANT(bool, is_exact = true); |
114 | BOOST_STATIC_CONSTANT(int, radix = 2); |
115 | static BOOST_ULLT epsilon() throw() { return 0; }; |
116 | static BOOST_ULLT round_error() throw() { return 0; }; |
117 | |
118 | BOOST_STATIC_CONSTANT(int, min_exponent = 0); |
119 | BOOST_STATIC_CONSTANT(int, min_exponent10 = 0); |
120 | BOOST_STATIC_CONSTANT(int, max_exponent = 0); |
121 | BOOST_STATIC_CONSTANT(int, max_exponent10 = 0); |
122 | |
123 | BOOST_STATIC_CONSTANT(bool, has_infinity = false); |
124 | BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = false); |
125 | BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = false); |
126 | BOOST_STATIC_CONSTANT(bool, has_denorm = false); |
127 | BOOST_STATIC_CONSTANT(bool, has_denorm_loss = false); |
128 | static BOOST_ULLT infinity() throw() { return 0; }; |
129 | static BOOST_ULLT quiet_NaN() throw() { return 0; }; |
130 | static BOOST_ULLT signaling_NaN() throw() { return 0; }; |
131 | static BOOST_ULLT denorm_min() throw() { return 0; }; |
132 | |
133 | BOOST_STATIC_CONSTANT(bool, is_iec559 = false); |
134 | BOOST_STATIC_CONSTANT(bool, is_bounded = true); |
135 | BOOST_STATIC_CONSTANT(bool, is_modulo = true); |
136 | |
137 | BOOST_STATIC_CONSTANT(bool, traps = false); |
138 | BOOST_STATIC_CONSTANT(bool, tinyness_before = false); |
139 | BOOST_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero); |
140 | |
141 | }; |
142 | } |
143 | #endif |
144 | |
145 | #endif |
146 | |
147 | |