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