limits.hpp 6.2 KB

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