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 11 #ifndef BOOST_UNITS_LIMITS_HPP 12 #define BOOST_UNITS_LIMITS_HPP 13 14 /// 15 /// \file 16 /// \brief specialize std::numeric_limits for units. 17 /// 18 19 #include <limits> 20 21 #include <boost/config.hpp> 22 #include <boost/units/units_fwd.hpp> 23 24 namespace std { 25 26 template<class Unit, class T> 27 class numeric_limits< ::boost::units::quantity<Unit, T> > 28 { 29 public: 30 typedef ::boost::units::quantity<Unit, T> quantity_type; 31 BOOST_STATIC_CONSTEXPR bool is_specialized = std::numeric_limits<T>::is_specialized; quantity_type(min)32 static BOOST_CONSTEXPR quantity_type (min)() { return(quantity_type::from_value((std::numeric_limits<T>::min)())); } quantity_type(max)33 static BOOST_CONSTEXPR quantity_type (max)() { return(quantity_type::from_value((std::numeric_limits<T>::max)())); } 34 #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS quantity_type(lowest)35 static BOOST_CONSTEXPR quantity_type (lowest)() { return(quantity_type::from_value((std::numeric_limits<T>::lowest)())); } 36 #endif 37 BOOST_STATIC_CONSTEXPR int digits = std::numeric_limits<T>::digits; 38 BOOST_STATIC_CONSTEXPR int digits10 = std::numeric_limits<T>::digits10; 39 #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS 40 BOOST_STATIC_CONSTEXPR int max_digits10 = std::numeric_limits<T>::max_digits10; 41 #endif 42 BOOST_STATIC_CONSTEXPR bool is_signed = std::numeric_limits<T>::is_signed; 43 BOOST_STATIC_CONSTEXPR bool is_integer = std::numeric_limits<T>::is_integer; 44 BOOST_STATIC_CONSTEXPR bool is_exact = std::numeric_limits<T>::is_exact; 45 BOOST_STATIC_CONSTEXPR int radix = std::numeric_limits<T>::radix; epsilon()46 static BOOST_CONSTEXPR quantity_type epsilon() { return(quantity_type::from_value(std::numeric_limits<T>::epsilon())); } round_error()47 static BOOST_CONSTEXPR quantity_type round_error() { return(quantity_type::from_value(std::numeric_limits<T>::round_error())); } 48 BOOST_STATIC_CONSTEXPR int min_exponent = std::numeric_limits<T>::min_exponent; 49 BOOST_STATIC_CONSTEXPR int min_exponent10 = std::numeric_limits<T>::min_exponent10; 50 BOOST_STATIC_CONSTEXPR int max_exponent = std::numeric_limits<T>::max_exponent; 51 BOOST_STATIC_CONSTEXPR int max_exponent10 = std::numeric_limits<T>::max_exponent10; 52 BOOST_STATIC_CONSTEXPR bool has_infinity = std::numeric_limits<T>::has_infinity; 53 BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = std::numeric_limits<T>::has_quiet_NaN; 54 BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = std::numeric_limits<T>::has_signaling_NaN; 55 BOOST_STATIC_CONSTEXPR bool has_denorm_loss = std::numeric_limits<T>::has_denorm_loss; infinity()56 static BOOST_CONSTEXPR quantity_type infinity() { return(quantity_type::from_value(std::numeric_limits<T>::infinity())); } quiet_NaN()57 static BOOST_CONSTEXPR quantity_type quiet_NaN() { return(quantity_type::from_value(std::numeric_limits<T>::quiet_NaN())); } signaling_NaN()58 static BOOST_CONSTEXPR quantity_type signaling_NaN() { return(quantity_type::from_value(std::numeric_limits<T>::signaling_NaN())); } denorm_min()59 static BOOST_CONSTEXPR quantity_type denorm_min() { return(quantity_type::from_value(std::numeric_limits<T>::denorm_min())); } 60 BOOST_STATIC_CONSTEXPR bool is_iec559 = std::numeric_limits<T>::is_iec559; 61 BOOST_STATIC_CONSTEXPR bool is_bounded = std::numeric_limits<T>::is_bounded; 62 BOOST_STATIC_CONSTEXPR bool is_modulo = std::numeric_limits<T>::is_modulo; 63 BOOST_STATIC_CONSTEXPR bool traps = std::numeric_limits<T>::traps; 64 BOOST_STATIC_CONSTEXPR bool tinyness_before = std::numeric_limits<T>::tinyness_before; 65 #if defined(_STLP_STATIC_CONST_INIT_BUG) 66 BOOST_STATIC_CONSTEXPR int has_denorm = std::numeric_limits<T>::has_denorm; 67 BOOST_STATIC_CONSTEXPR int round_style = std::numeric_limits<T>::round_style; 68 #else 69 BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = std::numeric_limits<T>::has_denorm; 70 BOOST_STATIC_CONSTEXPR float_round_style round_style = std::numeric_limits<T>::round_style; 71 #endif 72 }; 73 74 } 75 76 #endif // BOOST_UNITS_LIMITS_HPP 77