limits.hpp 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2007-2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_UNITS_LIMITS_HPP
  11. #define BOOST_UNITS_LIMITS_HPP
  12. ///
  13. /// \file
  14. /// \brief specialize std::numeric_limits for units.
  15. ///
  16. #include <limits>
  17. #include <boost/config.hpp>
  18. #include <boost/units/units_fwd.hpp>
  19. namespace std {
  20. template<class Unit, class T>
  21. class numeric_limits< ::boost::units::quantity<Unit, T> >
  22. {
  23. public:
  24. typedef ::boost::units::quantity<Unit, T> quantity_type;
  25. BOOST_STATIC_CONSTEXPR bool is_specialized = std::numeric_limits<T>::is_specialized;
  26. static BOOST_CONSTEXPR quantity_type (min)() { return(quantity_type::from_value((std::numeric_limits<T>::min)())); }
  27. static BOOST_CONSTEXPR quantity_type (max)() { return(quantity_type::from_value((std::numeric_limits<T>::max)())); }
  28. #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
  29. static BOOST_CONSTEXPR quantity_type (lowest)() { return(quantity_type::from_value((std::numeric_limits<T>::lowest)())); }
  30. #endif
  31. BOOST_STATIC_CONSTEXPR int digits = std::numeric_limits<T>::digits;
  32. BOOST_STATIC_CONSTEXPR int digits10 = std::numeric_limits<T>::digits10;
  33. #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
  34. BOOST_STATIC_CONSTEXPR int max_digits10 = std::numeric_limits<T>::max_digits10;
  35. #endif
  36. BOOST_STATIC_CONSTEXPR bool is_signed = std::numeric_limits<T>::is_signed;
  37. BOOST_STATIC_CONSTEXPR bool is_integer = std::numeric_limits<T>::is_integer;
  38. BOOST_STATIC_CONSTEXPR bool is_exact = std::numeric_limits<T>::is_exact;
  39. BOOST_STATIC_CONSTEXPR int radix = std::numeric_limits<T>::radix;
  40. static BOOST_CONSTEXPR quantity_type epsilon() { return(quantity_type::from_value(std::numeric_limits<T>::epsilon())); }
  41. static BOOST_CONSTEXPR quantity_type round_error() { return(quantity_type::from_value(std::numeric_limits<T>::round_error())); }
  42. BOOST_STATIC_CONSTEXPR int min_exponent = std::numeric_limits<T>::min_exponent;
  43. BOOST_STATIC_CONSTEXPR int min_exponent10 = std::numeric_limits<T>::min_exponent10;
  44. BOOST_STATIC_CONSTEXPR int max_exponent = std::numeric_limits<T>::max_exponent;
  45. BOOST_STATIC_CONSTEXPR int max_exponent10 = std::numeric_limits<T>::max_exponent10;
  46. BOOST_STATIC_CONSTEXPR bool has_infinity = std::numeric_limits<T>::has_infinity;
  47. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = std::numeric_limits<T>::has_quiet_NaN;
  48. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = std::numeric_limits<T>::has_signaling_NaN;
  49. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = std::numeric_limits<T>::has_denorm_loss;
  50. static BOOST_CONSTEXPR quantity_type infinity() { return(quantity_type::from_value(std::numeric_limits<T>::infinity())); }
  51. static BOOST_CONSTEXPR quantity_type quiet_NaN() { return(quantity_type::from_value(std::numeric_limits<T>::quiet_NaN())); }
  52. static BOOST_CONSTEXPR quantity_type signaling_NaN() { return(quantity_type::from_value(std::numeric_limits<T>::signaling_NaN())); }
  53. static BOOST_CONSTEXPR quantity_type denorm_min() { return(quantity_type::from_value(std::numeric_limits<T>::denorm_min())); }
  54. BOOST_STATIC_CONSTEXPR bool is_iec559 = std::numeric_limits<T>::is_iec559;
  55. BOOST_STATIC_CONSTEXPR bool is_bounded = std::numeric_limits<T>::is_bounded;
  56. BOOST_STATIC_CONSTEXPR bool is_modulo = std::numeric_limits<T>::is_modulo;
  57. BOOST_STATIC_CONSTEXPR bool traps = std::numeric_limits<T>::traps;
  58. BOOST_STATIC_CONSTEXPR bool tinyness_before = std::numeric_limits<T>::tinyness_before;
  59. #if defined(_STLP_STATIC_CONST_INIT_BUG)
  60. BOOST_STATIC_CONSTEXPR int has_denorm = std::numeric_limits<T>::has_denorm;
  61. BOOST_STATIC_CONSTEXPR int round_style = std::numeric_limits<T>::round_style;
  62. #else
  63. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = std::numeric_limits<T>::has_denorm;
  64. BOOST_STATIC_CONSTEXPR float_round_style round_style = std::numeric_limits<T>::round_style;
  65. #endif
  66. };
  67. }
  68. #endif // BOOST_UNITS_LIMITS_HPP