Ticket #9017: rational.hpp.patch

File rational.hpp.patch, 4.6 KB (added by awulkiew, 9 years ago)
  • rational.hpp

     
    2121//    Nickolay Mladenov, for the implementation of operator+=
    2222
    2323//  Revision History
     24//  05 Sep 13  Added preliminary version of numeric_limits<> specialization
     25//             (Adam Wulkiewicz)
    2426//  02 Sep 13  Remove unneeded forward declarations; tweak private helper
    2527//             function (Daryle Walker)
    2628//  30 Aug 13  Improve exception safety of "assign"; start modernizing I/O code
     
    8284#include <boost/math/common_factor_rt.hpp>  // for boost::math::gcd, lcm
    8385#include <limits>                // for std::numeric_limits
    8486#include <boost/static_assert.hpp>  // for BOOST_STATIC_ASSERT
     87#include <boost/config.hpp>      // for BOOST_CONSTEXPR, BOOST_CONSTEXPR_OR_CONST and BOOST_NOEXCEPT
    8588
    8689// Control whether depreciated GCD and LCM functions are included (default: yes)
    8790#ifndef BOOST_CONTROL_RATIONAL_HAS_GCD
     
    674677
    675678} // namespace boost
    676679
     680namespace std {
     681
     682template<typename IntType>
     683struct numeric_limits< ::boost::rational<IntType> >
     684{
     685    static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true;
     686    static BOOST_CONSTEXPR_OR_CONST bool is_signed = ::std::numeric_limits<IntType>::is_signed;
     687    static BOOST_CONSTEXPR_OR_CONST bool is_integer = false;
     688    static BOOST_CONSTEXPR_OR_CONST bool is_exact = true;
     689   
     690    static BOOST_CONSTEXPR_OR_CONST bool has_infinity = false;
     691    static BOOST_CONSTEXPR_OR_CONST bool has_quiet_NaN = false;
     692    static BOOST_CONSTEXPR_OR_CONST bool has_signaling_NaN = false;
     693
     694    static BOOST_CONSTEXPR_OR_CONST std::float_denorm_style has_denorm = std::denorm_absent;
     695    static BOOST_CONSTEXPR_OR_CONST bool has_denorm_loss = false;
     696    static BOOST_CONSTEXPR_OR_CONST float_round_style round_style = round_toward_zero;
     697    static BOOST_CONSTEXPR_OR_CONST bool is_iec559 = false;
     698    static BOOST_CONSTEXPR_OR_CONST bool is_bounded = true;
     699    static BOOST_CONSTEXPR_OR_CONST bool is_modulo = false;
     700   
     701    static BOOST_CONSTEXPR_OR_CONST int digits = ::std::numeric_limits<IntType>::digits;
     702    static BOOST_CONSTEXPR_OR_CONST int digits10 = ::std::numeric_limits<IntType>::digits10;
     703    // Add #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS ?
     704    static BOOST_CONSTEXPR_OR_CONST int max_digits10 = 0;
     705    static BOOST_CONSTEXPR_OR_CONST int radix = ::std::numeric_limits<IntType>::radix;
     706    static BOOST_CONSTEXPR_OR_CONST int min_exponent = 0;
     707    static BOOST_CONSTEXPR_OR_CONST int min_exponent10 = 0;
     708    static BOOST_CONSTEXPR_OR_CONST int max_exponent = 0;
     709    static BOOST_CONSTEXPR_OR_CONST int max_exponent10 = 0;
     710
     711    static BOOST_CONSTEXPR_OR_CONST bool traps = true;
     712    static BOOST_CONSTEXPR_OR_CONST bool tinyness_before = false;
     713
     714    static BOOST_CONSTEXPR ::boost::rational<IntType> (min)() BOOST_NOEXCEPT
     715    {
     716        return ::boost::rational<IntType>(
     717            1,
     718            (::std::numeric_limits<IntType>::max)());
     719    }
     720    // Add #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS ?
     721    static BOOST_CONSTEXPR ::boost::rational<IntType> lowest() BOOST_NOEXCEPT
     722    {
     723        return ::boost::rational<IntType>(
     724            (::std::numeric_limits<IntType>::min)(), // or -(::std::numeric_limits<IntType>::max)() ?
     725            (::std::numeric_limits<IntType>::max)());
     726    }
     727    static BOOST_CONSTEXPR ::boost::rational<IntType> (max)() BOOST_NOEXCEPT
     728    {
     729        return ::boost::rational<IntType>(
     730            (::std::numeric_limits<IntType>::max)(),
     731            1);
     732    }
     733    static BOOST_CONSTEXPR ::boost::rational<IntType> epsilon() BOOST_NOEXCEPT
     734    {
     735        return ::boost::rational<IntType>(
     736            1,
     737            (::std::numeric_limits<IntType>::max)());
     738    }
     739    static BOOST_CONSTEXPR ::boost::rational<IntType> denorm_min() BOOST_NOEXCEPT
     740    {
     741        return ::boost::rational<IntType>(
     742            1,
     743            (::std::numeric_limits<IntType>::max)());
     744    }
     745    static BOOST_CONSTEXPR ::boost::rational<IntType> round_error() BOOST_NOEXCEPT
     746    {
     747        return ::boost::rational<IntType>(1, 1);
     748    }
     749    static BOOST_CONSTEXPR ::boost::rational<IntType> infinity() BOOST_NOEXCEPT
     750    {
     751        return ::boost::rational<IntType>(0, 1);
     752    }
     753    static BOOST_CONSTEXPR ::boost::rational<IntType> quiet_NaN() BOOST_NOEXCEPT
     754    {
     755        return ::boost::rational<IntType>(0, 1);
     756    }
     757    static BOOST_CONSTEXPR ::boost::rational<IntType> signaling_NaN() BOOST_NOEXCEPT
     758    {
     759        return ::boost::rational<IntType>(0, 1);
     760    }
     761};
     762
     763} // namespace std
     764
    677765#endif  // BOOST_RATIONAL_HPP
    678766