/////////////////////////////////////////////////////////////// // Copyright 2012 John Maddock. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt // // Comparison operators for cpp_int_backend: // #ifndef BOOST_MP_CPP_INT_LIM_HPP #define BOOST_MP_CPP_INT_LIM_HPP #include namespace std { namespace detail { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4307) #endif template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bounded, signed, and no allocator. using result_type = boost::multiprecision::number, ExpressionTemplates> ; using ui_type = boost::multiprecision::number, ExpressionTemplates>; #ifdef BOOST_MP_NO_CONSTEXPR_DETECTION static #else constexpr #endif const result_type val = -result_type(~ui_type(0)); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bounded, signed, and an allocator (can't be constexpr). using result_type = boost::multiprecision::number, ExpressionTemplates> ; using ui_type = boost::multiprecision::number, ExpressionTemplates>; static const result_type val = -result_type(~ui_type(0)); return val; } template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bounded, unsigned, no allocator (can be constexpr): #ifdef BOOST_MP_NO_CONSTEXPR_DETECTION static #else constexpr #endif const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bounded and unsigned with allocator (no constexpr): static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Unbounded and signed, never constexpr because there must be an allocator. // 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 std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Unbound and unsigned, never constexpr because there must be an allocator. static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bounded and signed, no allocator, can be constexpr. using result_type = boost::multiprecision::number, ExpressionTemplates> ; using ui_type = boost::multiprecision::number, ExpressionTemplates>; #ifdef BOOST_MP_NO_CONSTEXPR_DETECTION static #else constexpr #endif const result_type val = ~ui_type(0); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bounded and signed, has an allocator, never constexpr. using result_type = boost::multiprecision::number, ExpressionTemplates> ; using ui_type = boost::multiprecision::number, ExpressionTemplates>; static const result_type val = ~ui_type(0); return val; } template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bound and unsigned, no allocator so can be constexpr: using result_type = boost::multiprecision::number, ExpressionTemplates> ; using ui_type = boost::multiprecision::number, ExpressionTemplates>; #ifdef BOOST_MP_NO_CONSTEXPR_DETECTION static #else constexpr #endif const result_type val = ~ui_type(0); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Bound and unsigned, has an allocator so can never be constexpr: using result_type = boost::multiprecision::number, ExpressionTemplates> ; using ui_type = boost::multiprecision::number, ExpressionTemplates>; static const result_type val = ~ui_type(0); return val; } template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // 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 std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { // Unbound and unsigned: static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } } // namespace detail template class numeric_limits, ExpressionTemplates> > { using backend_type = boost::multiprecision::cpp_int_backend; using number_type = boost::multiprecision::number ; public: static constexpr bool is_specialized = true; // // Largest and smallest numbers are bounded only by available memory, set // to zero: // static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type(min)() { return detail::get_min(boost::multiprecision::backends::is_fixed_precision(), boost::multiprecision::is_signed_number(), std::integral_constant::value>()); } static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type(max)() { return detail::get_max(boost::multiprecision::backends::is_fixed_precision(), boost::multiprecision::is_signed_number(), std::integral_constant::value>()); } static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type lowest() { return (min)(); } static constexpr int digits = boost::multiprecision::backends::max_precision::value == UINT_MAX ? INT_MAX : boost::multiprecision::backends::max_precision::value; static constexpr int digits10 = boost::multiprecision::detail::calc_digits10::value; static constexpr int max_digits10 = boost::multiprecision::detail::calc_max_digits10::value; static constexpr bool is_signed = boost::multiprecision::is_signed_number::value; static constexpr bool is_integer = true; static constexpr bool is_exact = true; static constexpr int radix = 2; static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type epsilon() { return 0; } static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type round_error() { return 0; } static constexpr int min_exponent = 0; static constexpr int min_exponent10 = 0; static constexpr int max_exponent = 0; static constexpr int max_exponent10 = 0; static constexpr bool has_infinity = false; static constexpr bool has_quiet_NaN = false; static constexpr bool has_signaling_NaN = false; static constexpr float_denorm_style has_denorm = denorm_absent; static constexpr bool has_denorm_loss = false; static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type infinity() { return 0; } static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type quiet_NaN() { return 0; } static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type signaling_NaN() { return 0; } static BOOST_CXX14_CONSTEXPR_IF_DETECTION number_type denorm_min() { return 0; } static constexpr bool is_iec559 = false; static constexpr bool is_bounded = boost::multiprecision::backends::is_fixed_precision::value; static constexpr bool is_modulo = (boost::multiprecision::backends::is_fixed_precision::value && (Checked == boost::multiprecision::unchecked)); static constexpr bool traps = false; static constexpr bool tinyness_before = false; static constexpr float_round_style round_style = round_toward_zero; }; template constexpr int numeric_limits, ExpressionTemplates> >::digits; template constexpr int numeric_limits, ExpressionTemplates> >::digits10; template constexpr int numeric_limits, ExpressionTemplates> >::max_digits10; template constexpr bool numeric_limits, ExpressionTemplates> >::is_signed; template constexpr bool numeric_limits, ExpressionTemplates> >::is_integer; template constexpr bool numeric_limits, ExpressionTemplates> >::is_exact; template constexpr int numeric_limits, ExpressionTemplates> >::radix; template constexpr int numeric_limits, ExpressionTemplates> >::min_exponent; template constexpr int numeric_limits, ExpressionTemplates> >::min_exponent10; template constexpr int numeric_limits, ExpressionTemplates> >::max_exponent; template constexpr int numeric_limits, ExpressionTemplates> >::max_exponent10; template constexpr bool numeric_limits, ExpressionTemplates> >::has_infinity; template constexpr bool numeric_limits, ExpressionTemplates> >::has_quiet_NaN; template constexpr bool numeric_limits, ExpressionTemplates> >::has_signaling_NaN; template constexpr float_denorm_style numeric_limits, ExpressionTemplates> >::has_denorm; template constexpr bool numeric_limits, ExpressionTemplates> >::has_denorm_loss; template constexpr bool numeric_limits, ExpressionTemplates> >::is_iec559; template constexpr bool numeric_limits, ExpressionTemplates> >::is_bounded; template constexpr bool numeric_limits, ExpressionTemplates> >::is_modulo; template constexpr bool numeric_limits, ExpressionTemplates> >::traps; template constexpr bool numeric_limits, ExpressionTemplates> >::tinyness_before; template constexpr float_round_style numeric_limits, ExpressionTemplates> >::round_style; #ifdef _MSC_VER #pragma warning(pop) #endif } // namespace std #endif