Index: rational.hpp =================================================================== --- rational.hpp (revision 85565) +++ rational.hpp (working copy) @@ -21,6 +21,8 @@ // Nickolay Mladenov, for the implementation of operator+= // Revision History +// 05 Sep 13 Added preliminary version of numeric_limits<> specialization +// (Adam Wulkiewicz) // 02 Sep 13 Remove unneeded forward declarations; tweak private helper // function (Daryle Walker) // 30 Aug 13 Improve exception safety of "assign"; start modernizing I/O code @@ -82,6 +84,7 @@ #include // for boost::math::gcd, lcm #include // for std::numeric_limits #include // for BOOST_STATIC_ASSERT +#include // for BOOST_CONSTEXPR, BOOST_CONSTEXPR_OR_CONST and BOOST_NOEXCEPT // Control whether depreciated GCD and LCM functions are included (default: yes) #ifndef BOOST_CONTROL_RATIONAL_HAS_GCD @@ -674,5 +677,90 @@ } // namespace boost +namespace std { + +template +struct numeric_limits< ::boost::rational > +{ + static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true; + static BOOST_CONSTEXPR_OR_CONST bool is_signed = ::std::numeric_limits::is_signed; + static BOOST_CONSTEXPR_OR_CONST bool is_integer = false; + static BOOST_CONSTEXPR_OR_CONST bool is_exact = true; + + static BOOST_CONSTEXPR_OR_CONST bool has_infinity = false; + static BOOST_CONSTEXPR_OR_CONST bool has_quiet_NaN = false; + static BOOST_CONSTEXPR_OR_CONST bool has_signaling_NaN = false; + + static BOOST_CONSTEXPR_OR_CONST std::float_denorm_style has_denorm = std::denorm_absent; + static BOOST_CONSTEXPR_OR_CONST bool has_denorm_loss = false; + static BOOST_CONSTEXPR_OR_CONST float_round_style round_style = round_toward_zero; + static BOOST_CONSTEXPR_OR_CONST bool is_iec559 = false; + static BOOST_CONSTEXPR_OR_CONST bool is_bounded = true; + static BOOST_CONSTEXPR_OR_CONST bool is_modulo = false; + + static BOOST_CONSTEXPR_OR_CONST int digits = ::std::numeric_limits::digits; + static BOOST_CONSTEXPR_OR_CONST int digits10 = ::std::numeric_limits::digits10; + // Add #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS ? + static BOOST_CONSTEXPR_OR_CONST int max_digits10 = 0; + static BOOST_CONSTEXPR_OR_CONST int radix = ::std::numeric_limits::radix; + static BOOST_CONSTEXPR_OR_CONST int min_exponent = 0; + static BOOST_CONSTEXPR_OR_CONST int min_exponent10 = 0; + static BOOST_CONSTEXPR_OR_CONST int max_exponent = 0; + static BOOST_CONSTEXPR_OR_CONST int max_exponent10 = 0; + + static BOOST_CONSTEXPR_OR_CONST bool traps = true; + static BOOST_CONSTEXPR_OR_CONST bool tinyness_before = false; + + static BOOST_CONSTEXPR ::boost::rational (min)() BOOST_NOEXCEPT + { + return ::boost::rational( + 1, + (::std::numeric_limits::max)()); + } + // Add #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS ? + static BOOST_CONSTEXPR ::boost::rational lowest() BOOST_NOEXCEPT + { + return ::boost::rational( + (::std::numeric_limits::min)(), // or -(::std::numeric_limits::max)() ? + (::std::numeric_limits::max)()); + } + static BOOST_CONSTEXPR ::boost::rational (max)() BOOST_NOEXCEPT + { + return ::boost::rational( + (::std::numeric_limits::max)(), + 1); + } + static BOOST_CONSTEXPR ::boost::rational epsilon() BOOST_NOEXCEPT + { + return ::boost::rational( + 1, + (::std::numeric_limits::max)()); + } + static BOOST_CONSTEXPR ::boost::rational denorm_min() BOOST_NOEXCEPT + { + return ::boost::rational( + 1, + (::std::numeric_limits::max)()); + } + static BOOST_CONSTEXPR ::boost::rational round_error() BOOST_NOEXCEPT + { + return ::boost::rational(1, 1); + } + static BOOST_CONSTEXPR ::boost::rational infinity() BOOST_NOEXCEPT + { + return ::boost::rational(0, 1); + } + static BOOST_CONSTEXPR ::boost::rational quiet_NaN() BOOST_NOEXCEPT + { + return ::boost::rational(0, 1); + } + static BOOST_CONSTEXPR ::boost::rational signaling_NaN() BOOST_NOEXCEPT + { + return ::boost::rational(0, 1); + } +}; + +} // namespace std + #endif // BOOST_RATIONAL_HPP