limits.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 BHO_LIMITS
  9. #define BHO_LIMITS
  10. #include <asio2/bho/config.hpp>
  11. #ifdef BHO_NO_LIMITS
  12. # error "There is no std::numeric_limits suppport available."
  13. #else
  14. # include <limits>
  15. #endif
  16. #if (!defined(BOOST_LLT)) && (!defined(BOOST_ULLT)) \
  17. && ((defined(BHO_HAS_LONG_LONG) && defined(BHO_NO_LONG_LONG_NUMERIC_LIMITS)) \
  18. || (defined(BHO_HAS_MS_INT64 ) && defined(BHO_NO_MS_INT64_NUMERIC_LIMITS )))
  19. // Add missing specializations for numeric_limits:
  20. #ifdef BHO_HAS_MS_INT64
  21. # define BHO_LLT __int64
  22. # define BHO_ULLT unsigned __int64
  23. #else
  24. # define BHO_LLT ::bho::long_long_type
  25. # define BHO_ULLT ::bho::ulong_long_type
  26. #endif
  27. #include <climits> // for CHAR_BIT
  28. namespace std
  29. {
  30. template<>
  31. class numeric_limits<BHO_LLT>
  32. {
  33. public:
  34. BHO_STATIC_CONSTANT(bool, is_specialized = true);
  35. #ifdef BHO_HAS_MS_INT64
  36. static BHO_LLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return 0x8000000000000000i64; }
  37. static BHO_LLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return 0x7FFFFFFFFFFFFFFFi64; }
  38. #elif defined(LLONG_MAX)
  39. static BHO_LLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return LLONG_MIN; }
  40. static BHO_LLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return LLONG_MAX; }
  41. #elif defined(LONGLONG_MAX)
  42. static BHO_LLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return LONGLONG_MIN; }
  43. static BHO_LLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return LONGLONG_MAX; }
  44. #else
  45. static BHO_LLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return 1LL << (sizeof(BHO_LLT) * CHAR_BIT - 1); }
  46. static BHO_LLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return ~(min)(); }
  47. #endif
  48. BHO_STATIC_CONSTANT(int, digits = sizeof(BHO_LLT) * CHAR_BIT -1);
  49. BHO_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BHO_LLT) - 1) * 301L / 1000);
  50. BHO_STATIC_CONSTANT(bool, is_signed = true);
  51. BHO_STATIC_CONSTANT(bool, is_integer = true);
  52. BHO_STATIC_CONSTANT(bool, is_exact = true);
  53. BHO_STATIC_CONSTANT(int, radix = 2);
  54. static BHO_LLT epsilon() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  55. static BHO_LLT round_error() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  56. BHO_STATIC_CONSTANT(int, min_exponent = 0);
  57. BHO_STATIC_CONSTANT(int, min_exponent10 = 0);
  58. BHO_STATIC_CONSTANT(int, max_exponent = 0);
  59. BHO_STATIC_CONSTANT(int, max_exponent10 = 0);
  60. BHO_STATIC_CONSTANT(bool, has_infinity = false);
  61. BHO_STATIC_CONSTANT(bool, has_quiet_NaN = false);
  62. BHO_STATIC_CONSTANT(bool, has_signaling_NaN = false);
  63. BHO_STATIC_CONSTANT(bool, has_denorm = false);
  64. BHO_STATIC_CONSTANT(bool, has_denorm_loss = false);
  65. static BHO_LLT infinity() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  66. static BHO_LLT quiet_NaN() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  67. static BHO_LLT signaling_NaN() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  68. static BHO_LLT denorm_min() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  69. BHO_STATIC_CONSTANT(bool, is_iec559 = false);
  70. BHO_STATIC_CONSTANT(bool, is_bounded = true);
  71. BHO_STATIC_CONSTANT(bool, is_modulo = true);
  72. BHO_STATIC_CONSTANT(bool, traps = false);
  73. BHO_STATIC_CONSTANT(bool, tinyness_before = false);
  74. BHO_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero);
  75. };
  76. template<>
  77. class numeric_limits<BHO_ULLT>
  78. {
  79. public:
  80. BHO_STATIC_CONSTANT(bool, is_specialized = true);
  81. #ifdef BHO_HAS_MS_INT64
  82. static BHO_ULLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return 0ui64; }
  83. static BHO_ULLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return 0xFFFFFFFFFFFFFFFFui64; }
  84. #elif defined(ULLONG_MAX) && defined(ULLONG_MIN)
  85. static BHO_ULLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MIN; }
  86. static BHO_ULLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MAX; }
  87. #elif defined(ULONGLONG_MAX) && defined(ULONGLONG_MIN)
  88. static BHO_ULLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MIN; }
  89. static BHO_ULLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MAX; }
  90. #else
  91. static BHO_ULLT min BHO_PREVENT_MACRO_SUBSTITUTION (){ return 0uLL; }
  92. static BHO_ULLT max BHO_PREVENT_MACRO_SUBSTITUTION (){ return ~0uLL; }
  93. #endif
  94. BHO_STATIC_CONSTANT(int, digits = sizeof(BHO_LLT) * CHAR_BIT);
  95. BHO_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BHO_LLT)) * 301L / 1000);
  96. BHO_STATIC_CONSTANT(bool, is_signed = false);
  97. BHO_STATIC_CONSTANT(bool, is_integer = true);
  98. BHO_STATIC_CONSTANT(bool, is_exact = true);
  99. BHO_STATIC_CONSTANT(int, radix = 2);
  100. static BHO_ULLT epsilon() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  101. static BHO_ULLT round_error() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  102. BHO_STATIC_CONSTANT(int, min_exponent = 0);
  103. BHO_STATIC_CONSTANT(int, min_exponent10 = 0);
  104. BHO_STATIC_CONSTANT(int, max_exponent = 0);
  105. BHO_STATIC_CONSTANT(int, max_exponent10 = 0);
  106. BHO_STATIC_CONSTANT(bool, has_infinity = false);
  107. BHO_STATIC_CONSTANT(bool, has_quiet_NaN = false);
  108. BHO_STATIC_CONSTANT(bool, has_signaling_NaN = false);
  109. BHO_STATIC_CONSTANT(bool, has_denorm = false);
  110. BHO_STATIC_CONSTANT(bool, has_denorm_loss = false);
  111. static BHO_ULLT infinity() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  112. static BHO_ULLT quiet_NaN() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  113. static BHO_ULLT signaling_NaN() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  114. static BHO_ULLT denorm_min() BHO_NOEXCEPT_OR_NOTHROW { return 0; };
  115. BHO_STATIC_CONSTANT(bool, is_iec559 = false);
  116. BHO_STATIC_CONSTANT(bool, is_bounded = true);
  117. BHO_STATIC_CONSTANT(bool, is_modulo = true);
  118. BHO_STATIC_CONSTANT(bool, traps = false);
  119. BHO_STATIC_CONSTANT(bool, tinyness_before = false);
  120. BHO_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero);
  121. };
  122. }
  123. #endif
  124. #endif