Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- limits ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_LIMITS |
| 12 | #define _LIBCPP_LIMITS |
| 13 | |
| 14 | /* |
| 15 | limits synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template<class T> |
| 21 | class numeric_limits |
| 22 | { |
| 23 | public: |
| 24 | static const bool is_specialized = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 25 | static T min() noexcept; |
| 26 | static T max() noexcept; |
| 27 | static T lowest() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | |
| 29 | static const int digits = 0; |
| 30 | static const int digits10 = 0; |
| 31 | static const int max_digits10 = 0; |
| 32 | static const bool is_signed = false; |
| 33 | static const bool is_integer = false; |
| 34 | static const bool is_exact = false; |
| 35 | static const int radix = 0; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 36 | static T epsilon() noexcept; |
| 37 | static T round_error() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | |
| 39 | static const int min_exponent = 0; |
| 40 | static const int min_exponent10 = 0; |
| 41 | static const int max_exponent = 0; |
| 42 | static const int max_exponent10 = 0; |
| 43 | |
| 44 | static const bool has_infinity = false; |
| 45 | static const bool has_quiet_NaN = false; |
| 46 | static const bool has_signaling_NaN = false; |
| 47 | static const float_denorm_style has_denorm = denorm_absent; |
| 48 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 49 | static T infinity() noexcept; |
| 50 | static T quiet_NaN() noexcept; |
| 51 | static T signaling_NaN() noexcept; |
| 52 | static T denorm_min() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | |
| 54 | static const bool is_iec559 = false; |
| 55 | static const bool is_bounded = false; |
| 56 | static const bool is_modulo = false; |
| 57 | |
| 58 | static const bool traps = false; |
| 59 | static const bool tinyness_before = false; |
| 60 | static const float_round_style round_style = round_toward_zero; |
| 61 | }; |
| 62 | |
| 63 | enum float_round_style |
| 64 | { |
| 65 | round_indeterminate = -1, |
| 66 | round_toward_zero = 0, |
| 67 | round_to_nearest = 1, |
| 68 | round_toward_infinity = 2, |
| 69 | round_toward_neg_infinity = 3 |
| 70 | }; |
| 71 | |
| 72 | enum float_denorm_style |
| 73 | { |
| 74 | denorm_indeterminate = -1, |
| 75 | denorm_absent = 0, |
| 76 | denorm_present = 1 |
| 77 | }; |
| 78 | |
| 79 | template<> class numeric_limits<cv bool>; |
| 80 | |
| 81 | template<> class numeric_limits<cv char>; |
| 82 | template<> class numeric_limits<cv signed char>; |
| 83 | template<> class numeric_limits<cv unsigned char>; |
| 84 | template<> class numeric_limits<cv wchar_t>; |
| 85 | template<> class numeric_limits<cv char16_t>; |
| 86 | template<> class numeric_limits<cv char32_t>; |
| 87 | |
| 88 | template<> class numeric_limits<cv short>; |
| 89 | template<> class numeric_limits<cv int>; |
| 90 | template<> class numeric_limits<cv long>; |
| 91 | template<> class numeric_limits<cv long long>; |
| 92 | template<> class numeric_limits<cv unsigned short>; |
| 93 | template<> class numeric_limits<cv unsigned int>; |
| 94 | template<> class numeric_limits<cv unsigned long>; |
| 95 | template<> class numeric_limits<cv unsigned long long>; |
| 96 | |
| 97 | template<> class numeric_limits<cv float>; |
| 98 | template<> class numeric_limits<cv double>; |
| 99 | template<> class numeric_limits<cv long double>; |
| 100 | |
| 101 | } // std |
| 102 | |
| 103 | */ |
| 104 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 105 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 107 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 108 | |
| 109 | #include <__config> |
| 110 | #include <type_traits> |
| 111 | |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame^] | 112 | #if defined(_MSC_VER) |
| 113 | #include "support/win32/limits_win32.h" |
| 114 | #endif // _MSC_VER |
| 115 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 117 | |
| 118 | enum float_round_style |
| 119 | { |
| 120 | round_indeterminate = -1, |
| 121 | round_toward_zero = 0, |
| 122 | round_to_nearest = 1, |
| 123 | round_toward_infinity = 2, |
| 124 | round_toward_neg_infinity = 3 |
| 125 | }; |
| 126 | |
| 127 | enum float_denorm_style |
| 128 | { |
| 129 | denorm_indeterminate = -1, |
| 130 | denorm_absent = 0, |
| 131 | denorm_present = 1 |
| 132 | }; |
| 133 | |
| 134 | template <class _Tp, bool = is_arithmetic<_Tp>::value> |
| 135 | class __libcpp_numeric_limits |
| 136 | { |
| 137 | protected: |
| 138 | typedef _Tp type; |
| 139 | |
| 140 | static const bool is_specialized = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 141 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return type();} |
| 142 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return type();} |
| 143 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return type();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
| 145 | static const int digits = 0; |
| 146 | static const int digits10 = 0; |
| 147 | static const int max_digits10 = 0; |
| 148 | static const bool is_signed = false; |
| 149 | static const bool is_integer = false; |
| 150 | static const bool is_exact = false; |
| 151 | static const int radix = 0; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 152 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return type();} |
| 153 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return type();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 | |
| 155 | static const int min_exponent = 0; |
| 156 | static const int min_exponent10 = 0; |
| 157 | static const int max_exponent = 0; |
| 158 | static const int max_exponent10 = 0; |
| 159 | |
| 160 | static const bool has_infinity = false; |
| 161 | static const bool has_quiet_NaN = false; |
| 162 | static const bool has_signaling_NaN = false; |
| 163 | static const float_denorm_style has_denorm = denorm_absent; |
| 164 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 165 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return type();} |
| 166 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return type();} |
| 167 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return type();} |
| 168 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return type();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | |
| 170 | static const bool is_iec559 = false; |
| 171 | static const bool is_bounded = false; |
| 172 | static const bool is_modulo = false; |
| 173 | |
| 174 | static const bool traps = false; |
| 175 | static const bool tinyness_before = false; |
| 176 | static const float_round_style round_style = round_toward_zero; |
| 177 | }; |
| 178 | |
| 179 | template <class _Tp, int digits, bool is_signed> |
| 180 | struct __libcpp_compute_min |
| 181 | { |
| 182 | static const _Tp value = _Tp(_Tp(1) << digits); |
| 183 | }; |
| 184 | |
| 185 | template <class _Tp, int digits> |
| 186 | struct __libcpp_compute_min<_Tp, digits, false> |
| 187 | { |
| 188 | static const _Tp value = _Tp(0); |
| 189 | }; |
| 190 | |
| 191 | template <class _Tp> |
| 192 | class __libcpp_numeric_limits<_Tp, true> |
| 193 | { |
| 194 | protected: |
| 195 | typedef _Tp type; |
| 196 | |
| 197 | static const bool is_specialized = true; |
| 198 | |
| 199 | static const bool is_signed = type(-1) < type(0); |
| 200 | static const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed); |
| 201 | static const int digits10 = digits * 3 / 10; |
| 202 | static const int max_digits10 = 0; |
| 203 | static const type __min = __libcpp_compute_min<type, digits, is_signed>::value; |
| 204 | static const type __max = is_signed ? type(type(~0) ^ __min) : type(~0); |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 205 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __min;} |
| 206 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __max;} |
| 207 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return min();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 208 | |
| 209 | static const bool is_integer = true; |
| 210 | static const bool is_exact = true; |
| 211 | static const int radix = 2; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 212 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return type(0);} |
| 213 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 | |
| 215 | static const int min_exponent = 0; |
| 216 | static const int min_exponent10 = 0; |
| 217 | static const int max_exponent = 0; |
| 218 | static const int max_exponent10 = 0; |
| 219 | |
| 220 | static const bool has_infinity = false; |
| 221 | static const bool has_quiet_NaN = false; |
| 222 | static const bool has_signaling_NaN = false; |
| 223 | static const float_denorm_style has_denorm = denorm_absent; |
| 224 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 225 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return type(0);} |
| 226 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return type(0);} |
| 227 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return type(0);} |
| 228 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 229 | |
| 230 | static const bool is_iec559 = false; |
| 231 | static const bool is_bounded = true; |
| 232 | static const bool is_modulo = true; |
| 233 | |
| 234 | #if __i386__ || __x86_64__ |
| 235 | static const bool traps = true; |
| 236 | #else |
| 237 | static const bool traps = false; |
| 238 | #endif |
| 239 | static const bool tinyness_before = false; |
| 240 | static const float_round_style round_style = round_toward_zero; |
| 241 | }; |
| 242 | |
| 243 | template <> |
| 244 | class __libcpp_numeric_limits<bool, true> |
| 245 | { |
| 246 | protected: |
| 247 | typedef bool type; |
| 248 | |
| 249 | static const bool is_specialized = true; |
| 250 | |
| 251 | static const bool is_signed = false; |
| 252 | static const int digits = 1; |
| 253 | static const int digits10 = 0; |
| 254 | static const int max_digits10 = 0; |
| 255 | static const type __min = false; |
| 256 | static const type __max = true; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 257 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __min;} |
| 258 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __max;} |
| 259 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return min();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | |
| 261 | static const bool is_integer = true; |
| 262 | static const bool is_exact = true; |
| 263 | static const int radix = 2; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 264 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return type(0);} |
| 265 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 | |
| 267 | static const int min_exponent = 0; |
| 268 | static const int min_exponent10 = 0; |
| 269 | static const int max_exponent = 0; |
| 270 | static const int max_exponent10 = 0; |
| 271 | |
| 272 | static const bool has_infinity = false; |
| 273 | static const bool has_quiet_NaN = false; |
| 274 | static const bool has_signaling_NaN = false; |
| 275 | static const float_denorm_style has_denorm = denorm_absent; |
| 276 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 277 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return type(0);} |
| 278 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return type(0);} |
| 279 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return type(0);} |
| 280 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | |
| 282 | static const bool is_iec559 = false; |
| 283 | static const bool is_bounded = true; |
| 284 | static const bool is_modulo = false; |
| 285 | |
| 286 | static const bool traps = false; |
| 287 | static const bool tinyness_before = false; |
| 288 | static const float_round_style round_style = round_toward_zero; |
| 289 | }; |
| 290 | |
| 291 | template <> |
| 292 | class __libcpp_numeric_limits<float, true> |
| 293 | { |
| 294 | protected: |
| 295 | typedef float type; |
| 296 | |
| 297 | static const bool is_specialized = true; |
| 298 | |
| 299 | static const bool is_signed = true; |
| 300 | static const int digits = __FLT_MANT_DIG__; |
| 301 | static const int digits10 = __FLT_DIG__; |
| 302 | static const int max_digits10 = 2+(digits * 30103)/100000; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 303 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __FLT_MIN__;} |
| 304 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __FLT_MAX__;} |
| 305 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return -max();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 306 | |
| 307 | static const bool is_integer = false; |
| 308 | static const bool is_exact = false; |
| 309 | static const int radix = __FLT_RADIX__; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 310 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __FLT_EPSILON__;} |
| 311 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return 0.5F;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | |
| 313 | static const int min_exponent = __FLT_MIN_EXP__; |
| 314 | static const int min_exponent10 = __FLT_MIN_10_EXP__; |
| 315 | static const int max_exponent = __FLT_MAX_EXP__; |
| 316 | static const int max_exponent10 = __FLT_MAX_10_EXP__; |
| 317 | |
| 318 | static const bool has_infinity = true; |
| 319 | static const bool has_quiet_NaN = true; |
| 320 | static const bool has_signaling_NaN = true; |
| 321 | static const float_denorm_style has_denorm = denorm_present; |
| 322 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 323 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __builtin_huge_valf();} |
| 324 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __builtin_nanf("");} |
| 325 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __builtin_nansf("");} |
| 326 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __FLT_DENORM_MIN__;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 327 | |
| 328 | static const bool is_iec559 = true; |
| 329 | static const bool is_bounded = true; |
| 330 | static const bool is_modulo = false; |
| 331 | |
| 332 | static const bool traps = false; |
| 333 | static const bool tinyness_before = false; |
| 334 | static const float_round_style round_style = round_to_nearest; |
| 335 | }; |
| 336 | |
| 337 | template <> |
| 338 | class __libcpp_numeric_limits<double, true> |
| 339 | { |
| 340 | protected: |
| 341 | typedef double type; |
| 342 | |
| 343 | static const bool is_specialized = true; |
| 344 | |
| 345 | static const bool is_signed = true; |
| 346 | static const int digits = __DBL_MANT_DIG__; |
| 347 | static const int digits10 = __DBL_DIG__; |
| 348 | static const int max_digits10 = 2+(digits * 30103)/100000; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 349 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __DBL_MIN__;} |
| 350 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __DBL_MAX__;} |
| 351 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return -max();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | |
| 353 | static const bool is_integer = false; |
| 354 | static const bool is_exact = false; |
| 355 | static const int radix = __FLT_RADIX__; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 356 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __DBL_EPSILON__;} |
| 357 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return 0.5;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | |
| 359 | static const int min_exponent = __DBL_MIN_EXP__; |
| 360 | static const int min_exponent10 = __DBL_MIN_10_EXP__; |
| 361 | static const int max_exponent = __DBL_MAX_EXP__; |
| 362 | static const int max_exponent10 = __DBL_MAX_10_EXP__; |
| 363 | |
| 364 | static const bool has_infinity = true; |
| 365 | static const bool has_quiet_NaN = true; |
| 366 | static const bool has_signaling_NaN = true; |
| 367 | static const float_denorm_style has_denorm = denorm_present; |
| 368 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 369 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __builtin_huge_val();} |
| 370 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __builtin_nan("");} |
| 371 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __builtin_nans("");} |
| 372 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __DBL_DENORM_MIN__;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | |
| 374 | static const bool is_iec559 = true; |
| 375 | static const bool is_bounded = true; |
| 376 | static const bool is_modulo = false; |
| 377 | |
| 378 | static const bool traps = false; |
| 379 | static const bool tinyness_before = false; |
| 380 | static const float_round_style round_style = round_to_nearest; |
| 381 | }; |
| 382 | |
| 383 | template <> |
| 384 | class __libcpp_numeric_limits<long double, true> |
| 385 | { |
| 386 | protected: |
| 387 | typedef long double type; |
| 388 | |
| 389 | static const bool is_specialized = true; |
| 390 | |
| 391 | static const bool is_signed = true; |
| 392 | static const int digits = __LDBL_MANT_DIG__; |
| 393 | static const int digits10 = __LDBL_DIG__; |
| 394 | static const int max_digits10 = 2+(digits * 30103)/100000; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 395 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __LDBL_MIN__;} |
| 396 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __LDBL_MAX__;} |
| 397 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return -max();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | |
| 399 | static const bool is_integer = false; |
| 400 | static const bool is_exact = false; |
| 401 | static const int radix = __FLT_RADIX__; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 402 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __LDBL_EPSILON__;} |
| 403 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return 0.5;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | static const int min_exponent = __LDBL_MIN_EXP__; |
| 406 | static const int min_exponent10 = __LDBL_MIN_10_EXP__; |
| 407 | static const int max_exponent = __LDBL_MAX_EXP__; |
| 408 | static const int max_exponent10 = __LDBL_MAX_10_EXP__; |
| 409 | |
| 410 | static const bool has_infinity = true; |
| 411 | static const bool has_quiet_NaN = true; |
| 412 | static const bool has_signaling_NaN = true; |
| 413 | static const float_denorm_style has_denorm = denorm_present; |
| 414 | static const bool has_denorm_loss = false; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 415 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __builtin_huge_vall();} |
| 416 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __builtin_nanl("");} |
| 417 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __builtin_nansl("");} |
| 418 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __LDBL_DENORM_MIN__;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | |
| 420 | #if (defined(__ppc__) || defined(__ppc64__)) |
| 421 | static const bool is_iec559 = false; |
| 422 | #else |
| 423 | static const bool is_iec559 = true; |
| 424 | #endif |
| 425 | static const bool is_bounded = true; |
| 426 | static const bool is_modulo = false; |
| 427 | |
| 428 | static const bool traps = false; |
| 429 | static const bool tinyness_before = false; |
| 430 | static const float_round_style round_style = round_to_nearest; |
| 431 | }; |
| 432 | |
| 433 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 434 | class _LIBCPP_VISIBLE numeric_limits |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 435 | : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type> |
| 436 | { |
| 437 | typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base; |
| 438 | typedef typename __base::type type; |
| 439 | public: |
| 440 | static const bool is_specialized = __base::is_specialized; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 441 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} |
| 442 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} |
| 443 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | |
| 445 | static const int digits = __base::digits; |
| 446 | static const int digits10 = __base::digits10; |
| 447 | static const int max_digits10 = __base::max_digits10; |
| 448 | static const bool is_signed = __base::is_signed; |
| 449 | static const bool is_integer = __base::is_integer; |
| 450 | static const bool is_exact = __base::is_exact; |
| 451 | static const int radix = __base::radix; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 452 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} |
| 453 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | |
| 455 | static const int min_exponent = __base::min_exponent; |
| 456 | static const int min_exponent10 = __base::min_exponent10; |
| 457 | static const int max_exponent = __base::max_exponent; |
| 458 | static const int max_exponent10 = __base::max_exponent10; |
| 459 | |
| 460 | static const bool has_infinity = __base::has_infinity; |
| 461 | static const bool has_quiet_NaN = __base::has_quiet_NaN; |
| 462 | static const bool has_signaling_NaN = __base::has_signaling_NaN; |
| 463 | static const float_denorm_style has_denorm = __base::has_denorm; |
| 464 | static const bool has_denorm_loss = __base::has_denorm_loss; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 465 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} |
| 466 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} |
| 467 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} |
| 468 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | |
| 470 | static const bool is_iec559 = __base::is_iec559; |
| 471 | static const bool is_bounded = __base::is_bounded; |
| 472 | static const bool is_modulo = __base::is_modulo; |
| 473 | |
| 474 | static const bool traps = __base::traps; |
| 475 | static const bool tinyness_before = __base::tinyness_before; |
| 476 | static const float_round_style round_style = __base::round_style; |
| 477 | }; |
| 478 | |
| 479 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 480 | class _LIBCPP_VISIBLE numeric_limits<const _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 481 | : private numeric_limits<_Tp> |
| 482 | { |
| 483 | typedef numeric_limits<_Tp> __base; |
| 484 | typedef _Tp type; |
| 485 | public: |
| 486 | static const bool is_specialized = __base::is_specialized; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 487 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} |
| 488 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} |
| 489 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 490 | |
| 491 | static const int digits = __base::digits; |
| 492 | static const int digits10 = __base::digits10; |
| 493 | static const int max_digits10 = __base::max_digits10; |
| 494 | static const bool is_signed = __base::is_signed; |
| 495 | static const bool is_integer = __base::is_integer; |
| 496 | static const bool is_exact = __base::is_exact; |
| 497 | static const int radix = __base::radix; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 498 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} |
| 499 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | |
| 501 | static const int min_exponent = __base::min_exponent; |
| 502 | static const int min_exponent10 = __base::min_exponent10; |
| 503 | static const int max_exponent = __base::max_exponent; |
| 504 | static const int max_exponent10 = __base::max_exponent10; |
| 505 | |
| 506 | static const bool has_infinity = __base::has_infinity; |
| 507 | static const bool has_quiet_NaN = __base::has_quiet_NaN; |
| 508 | static const bool has_signaling_NaN = __base::has_signaling_NaN; |
| 509 | static const float_denorm_style has_denorm = __base::has_denorm; |
| 510 | static const bool has_denorm_loss = __base::has_denorm_loss; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 511 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} |
| 512 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} |
| 513 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} |
| 514 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | |
| 516 | static const bool is_iec559 = __base::is_iec559; |
| 517 | static const bool is_bounded = __base::is_bounded; |
| 518 | static const bool is_modulo = __base::is_modulo; |
| 519 | |
| 520 | static const bool traps = __base::traps; |
| 521 | static const bool tinyness_before = __base::tinyness_before; |
| 522 | static const float_round_style round_style = __base::round_style; |
| 523 | }; |
| 524 | |
| 525 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 526 | class _LIBCPP_VISIBLE numeric_limits<volatile _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | : private numeric_limits<_Tp> |
| 528 | { |
| 529 | typedef numeric_limits<_Tp> __base; |
| 530 | typedef _Tp type; |
| 531 | public: |
| 532 | static const bool is_specialized = __base::is_specialized; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 533 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} |
| 534 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} |
| 535 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | |
| 537 | static const int digits = __base::digits; |
| 538 | static const int digits10 = __base::digits10; |
| 539 | static const int max_digits10 = __base::max_digits10; |
| 540 | static const bool is_signed = __base::is_signed; |
| 541 | static const bool is_integer = __base::is_integer; |
| 542 | static const bool is_exact = __base::is_exact; |
| 543 | static const int radix = __base::radix; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 544 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} |
| 545 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | |
| 547 | static const int min_exponent = __base::min_exponent; |
| 548 | static const int min_exponent10 = __base::min_exponent10; |
| 549 | static const int max_exponent = __base::max_exponent; |
| 550 | static const int max_exponent10 = __base::max_exponent10; |
| 551 | |
| 552 | static const bool has_infinity = __base::has_infinity; |
| 553 | static const bool has_quiet_NaN = __base::has_quiet_NaN; |
| 554 | static const bool has_signaling_NaN = __base::has_signaling_NaN; |
| 555 | static const float_denorm_style has_denorm = __base::has_denorm; |
| 556 | static const bool has_denorm_loss = __base::has_denorm_loss; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 557 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} |
| 558 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} |
| 559 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} |
| 560 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | |
| 562 | static const bool is_iec559 = __base::is_iec559; |
| 563 | static const bool is_bounded = __base::is_bounded; |
| 564 | static const bool is_modulo = __base::is_modulo; |
| 565 | |
| 566 | static const bool traps = __base::traps; |
| 567 | static const bool tinyness_before = __base::tinyness_before; |
| 568 | static const float_round_style round_style = __base::round_style; |
| 569 | }; |
| 570 | |
| 571 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 572 | class _LIBCPP_VISIBLE numeric_limits<const volatile _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 573 | : private numeric_limits<_Tp> |
| 574 | { |
| 575 | typedef numeric_limits<_Tp> __base; |
| 576 | typedef _Tp type; |
| 577 | public: |
| 578 | static const bool is_specialized = __base::is_specialized; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 579 | _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} |
| 580 | _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} |
| 581 | _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | |
| 583 | static const int digits = __base::digits; |
| 584 | static const int digits10 = __base::digits10; |
| 585 | static const int max_digits10 = __base::max_digits10; |
| 586 | static const bool is_signed = __base::is_signed; |
| 587 | static const bool is_integer = __base::is_integer; |
| 588 | static const bool is_exact = __base::is_exact; |
| 589 | static const int radix = __base::radix; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 590 | _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} |
| 591 | _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | |
| 593 | static const int min_exponent = __base::min_exponent; |
| 594 | static const int min_exponent10 = __base::min_exponent10; |
| 595 | static const int max_exponent = __base::max_exponent; |
| 596 | static const int max_exponent10 = __base::max_exponent10; |
| 597 | |
| 598 | static const bool has_infinity = __base::has_infinity; |
| 599 | static const bool has_quiet_NaN = __base::has_quiet_NaN; |
| 600 | static const bool has_signaling_NaN = __base::has_signaling_NaN; |
| 601 | static const float_denorm_style has_denorm = __base::has_denorm; |
| 602 | static const bool has_denorm_loss = __base::has_denorm_loss; |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 603 | _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} |
| 604 | _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} |
| 605 | _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} |
| 606 | _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | |
| 608 | static const bool is_iec559 = __base::is_iec559; |
| 609 | static const bool is_bounded = __base::is_bounded; |
| 610 | static const bool is_modulo = __base::is_modulo; |
| 611 | |
| 612 | static const bool traps = __base::traps; |
| 613 | static const bool tinyness_before = __base::tinyness_before; |
| 614 | static const float_round_style round_style = __base::round_style; |
| 615 | }; |
| 616 | |
| 617 | _LIBCPP_END_NAMESPACE_STD |
| 618 | |
| 619 | #endif // _LIBCPP_LIMITS |