limits.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2005-2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. //
  5. // On some platforms std::limits gives incorrect values for long double.
  6. // This tries to work around them.
  7. #if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_LIMITS_HEADER)
  8. #define BOOST_FUNCTIONAL_HASH_DETAIL_LIMITS_HEADER
  9. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  10. # pragma once
  11. #endif
  12. #include <boost/limits.hpp>
  13. // On OpenBSD, numeric_limits is not reliable for long doubles, but
  14. // the macros defined in <float.h> are and support long double when STLport
  15. // doesn't.
  16. #if defined(__OpenBSD__) || defined(_STLP_NO_LONG_DOUBLE)
  17. #include <float.h>
  18. #endif
  19. namespace boost
  20. {
  21. namespace hash_detail
  22. {
  23. template <class T>
  24. struct limits : std::numeric_limits<T> {};
  25. #if defined(__OpenBSD__) || defined(_STLP_NO_LONG_DOUBLE)
  26. template <>
  27. struct limits<long double>
  28. : std::numeric_limits<long double>
  29. {
  30. static long double epsilon() {
  31. return LDBL_EPSILON;
  32. }
  33. static long double (max)() {
  34. return LDBL_MAX;
  35. }
  36. static long double (min)() {
  37. return LDBL_MIN;
  38. }
  39. BOOST_STATIC_CONSTANT(int, digits = LDBL_MANT_DIG);
  40. BOOST_STATIC_CONSTANT(int, max_exponent = LDBL_MAX_EXP);
  41. BOOST_STATIC_CONSTANT(int, min_exponent = LDBL_MIN_EXP);
  42. #if defined(_STLP_NO_LONG_DOUBLE)
  43. BOOST_STATIC_CONSTANT(int, radix = FLT_RADIX);
  44. #endif
  45. };
  46. #endif // __OpenBSD__
  47. }
  48. }
  49. #endif