/////////////////////////////////////////////////////////////// // Copyright 2012 John Maddock. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_ // // Comparison operators for cpp_int_backend: // #ifndef BOOST_MP_CPP_INT_LIM_HPP #define BOOST_MP_CPP_INT_LIM_HPP namespace std{ namespace detail{ #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4307) #endif template inline boost::multiprecision::number, ExpressionTemplates> get_min(const boost::mpl::true_&, const boost::mpl::true_&) { // Bounded and signed. typedef boost::multiprecision::number, ExpressionTemplates> result_type; typedef boost::multiprecision::number, ExpressionTemplates> ui_type; static const result_type val = -result_type(~ui_type(0)); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_min(const boost::mpl::true_&, const boost::mpl::false_&) { // Bounded and unsigned: static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_min(const boost::mpl::false_&, const boost::mpl::true_&) { // Unbounded and signed. // There is no minimum value, just return 0: static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_min(const boost::mpl::false_&, const boost::mpl::false_&) { // Unbound and unsigned: static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const boost::mpl::true_&, const boost::mpl::true_&) { // Bounded and signed. typedef boost::multiprecision::number, ExpressionTemplates> result_type; typedef boost::multiprecision::number, ExpressionTemplates> ui_type; static const result_type val = ~ui_type(0); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const boost::mpl::true_&, const boost::mpl::false_&) { // Bound and unsigned: typedef boost::multiprecision::number, ExpressionTemplates> result_type; typedef boost::multiprecision::number, ExpressionTemplates> ui_type; static const result_type val = ~ui_type(0); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const boost::mpl::false_&, const boost::mpl::true_&) { // Unbounded and signed. // There is no maximum value, just return 0: static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const boost::mpl::false_&, const boost::mpl::false_&) { // Unbound and unsigned: static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } } template class numeric_limits, ExpressionTemplates> > { typedef boost::multiprecision::cpp_int_backend backend_type; typedef boost::multiprecision::number number_type; struct inititializer { inititializer() { (std::numeric_limits::max)(); (std::numeric_limits::min)(); } void do_nothing()const{} }; static const inititializer init; public: BOOST_STATIC_CONSTEXPR bool is_specialized = true; // // Largest and smallest numbers are bounded only by available memory, set // to zero: // static number_type (min)() { init.do_nothing(); return detail::get_min(boost::multiprecision::backends::is_fixed_precision(), boost::multiprecision::is_signed_number()); } static number_type (max)() { init.do_nothing(); return detail::get_max(boost::multiprecision::backends::is_fixed_precision(), boost::multiprecision::is_signed_number()); } static number_type lowest() { return (min)(); } BOOST_STATIC_CONSTEXPR int digits = boost::multiprecision::backends::max_precision::value == UINT_MAX ? INT_MAX : boost::multiprecision::backends::max_precision::value; BOOST_STATIC_CONSTEXPR int digits10 = (digits > INT_MAX / 301) ? (digits / 1000) * 301L : (digits * 301) / 1000; BOOST_STATIC_CONSTEXPR int max_digits10 = digits10 + 3; BOOST_STATIC_CONSTEXPR bool is_signed = boost::multiprecision::is_signed_number::value; BOOST_STATIC_CONSTEXPR bool is_integer = true; BOOST_STATIC_CONSTEXPR bool is_exact = true; BOOST_STATIC_CONSTEXPR int radix = 2; static number_type epsilon() { return 0; } static number_type round_error() { return 0; } BOOST_STATIC_CONSTEXPR int min_exponent = 0; BOOST_STATIC_CONSTEXPR int min_exponent10 = 0; BOOST_STATIC_CONSTEXPR int max_exponent = 0; BOOST_STATIC_CONSTEXPR int max_exponent10 = 0; BOOST_STATIC_CONSTEXPR bool has_infinity = false; BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false; BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false; BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent; BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false; static number_type infinity() { return 0; } static number_type quiet_NaN() { return 0; } static number_type signaling_NaN() { return 0; } static number_type denorm_min() { return 0; } BOOST_STATIC_CONSTEXPR bool is_iec559 = false; BOOST_STATIC_CONSTEXPR bool is_bounded = boost::multiprecision::backends::is_fixed_precision::value; BOOST_STATIC_CONSTEXPR bool is_modulo = (boost::multiprecision::backends::is_fixed_precision::value && (Checked == boost::multiprecision::unchecked)); BOOST_STATIC_CONSTEXPR bool traps = false; BOOST_STATIC_CONSTEXPR bool tinyness_before = false; BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero; }; template const typename numeric_limits, ExpressionTemplates> >::inititializer numeric_limits, ExpressionTemplates> >::init; #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::digits; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::digits10; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::max_digits10; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::is_signed; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::is_integer; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::is_exact; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::radix; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::min_exponent; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::min_exponent10; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::max_exponent; template BOOST_CONSTEXPR_OR_CONST int numeric_limits, ExpressionTemplates> >::max_exponent10; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::has_infinity; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::has_quiet_NaN; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::has_signaling_NaN; template BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits, ExpressionTemplates> >::has_denorm; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::has_denorm_loss; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::is_iec559; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::is_bounded; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::is_modulo; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::traps; template BOOST_CONSTEXPR_OR_CONST bool numeric_limits, ExpressionTemplates> >::tinyness_before; template BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits, ExpressionTemplates> >::round_style; #endif #ifdef _MSC_VER #pragma warning(pop) #endif } // namespace std #endif