limits.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include <boost/config.hpp>
  10. #if defined(BOOST_HAS_PRAGMA_ONCE)
  11. #pragma once
  12. #endif
  13. #include <boost/limits.hpp>
  14. // On OpenBSD, numeric_limits is not reliable for long doubles, but
  15. // the macros defined in <float.h> are and support long double when STLport
  16. // doesn't.
  17. #if defined(__OpenBSD__) || defined(_STLP_NO_LONG_DOUBLE)
  18. #include <float.h>
  19. #endif
  20. namespace boost
  21. {
  22. namespace hash_detail
  23. {
  24. template <class T>
  25. struct limits : std::numeric_limits<T> {};
  26. #if defined(__OpenBSD__) || defined(_STLP_NO_LONG_DOUBLE)
  27. template <>
  28. struct limits<long double>
  29. : std::numeric_limits<long double>
  30. {
  31. static long double epsilon() {
  32. return LDBL_EPSILON;
  33. }
  34. static long double (max)() {
  35. return LDBL_MAX;
  36. }
  37. static long double (min)() {
  38. return LDBL_MIN;
  39. }
  40. BOOST_STATIC_CONSTANT(int, digits = LDBL_MANT_DIG);
  41. BOOST_STATIC_CONSTANT(int, max_exponent = LDBL_MAX_EXP);
  42. BOOST_STATIC_CONSTANT(int, min_exponent = LDBL_MIN_EXP);
  43. #if defined(_STLP_NO_LONG_DOUBLE)
  44. BOOST_STATIC_CONSTANT(int, radix = FLT_RADIX);
  45. #endif
  46. };
  47. #endif // __OpenBSD__
  48. }
  49. }
  50. #endif