diff --git a/include/boost/multiprecision/detail/default_ops.hpp b/include/boost/multiprecision/detail/default_ops.hpp index 4b7e7f9b..0fd06b26 100644 --- a/include/boost/multiprecision/detail/default_ops.hpp +++ b/include/boost/multiprecision/detail/default_ops.hpp @@ -725,10 +725,16 @@ inline void eval_round(T& result, const T& a) } } +template +void eval_lcm(B& result, const B& a, const B& b); +template +void eval_gcd(B& result, const B& a, const B& b); + template inline typename enable_if >::type eval_gcd(T& result, const T& a, const Arithmetic& b) { typedef typename boost::multiprecision::detail::canonical::type si_type; + using default_ops::eval_gcd; T t; t = static_cast(b); eval_gcd(result, a, t); @@ -742,6 +748,7 @@ template inline typename enable_if >::type eval_lcm(T& result, const T& a, const Arithmetic& b) { typedef typename boost::multiprecision::detail::canonical::type si_type; + using default_ops::eval_lcm; T t; t = static_cast(b); eval_lcm(result, a, t); @@ -813,11 +820,6 @@ inline void eval_bit_unset(T& val, unsigned index) eval_bitwise_xor(val, mask); } -template -void eval_lcm(B& result, const B& a, const B& b); -template -void eval_gcd(B& result, const B& a, const B& b); - // // These have to implemented by the backend, declared here so that our macro generated code compiles OK. // diff --git a/include/boost/multiprecision/detail/generic_interconvert.hpp b/include/boost/multiprecision/detail/generic_interconvert.hpp index 2cda6a6e..526ec86a 100644 --- a/include/boost/multiprecision/detail/generic_interconvert.hpp +++ b/include/boost/multiprecision/detail/generic_interconvert.hpp @@ -66,6 +66,7 @@ void generic_interconvert(To& to, const From& from, const mpl::int_::type limb_type; // get the corresponding type that we can assign to "To": diff --git a/include/boost/multiprecision/detail/integer_ops.hpp b/include/boost/multiprecision/detail/integer_ops.hpp index 7cd7fb78..9e53e094 100644 --- a/include/boost/multiprecision/detail/integer_ops.hpp +++ b/include/boost/multiprecision/detail/integer_ops.hpp @@ -309,7 +309,7 @@ void eval_powm(Backend& result, const Backend& a, const Backend& p, Integer c) } template -void eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c) +typename enable_if >::type eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c) { typedef typename canonical::type ui_type; typedef typename canonical::type i_type; @@ -320,11 +320,6 @@ void eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c) using default_ops::eval_modulus; using default_ops::eval_right_shift; - if(b < 0) - { - BOOST_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent.")); - } - Backend x, y(a); x = ui_type(1u); while(b > 0) @@ -341,8 +336,18 @@ void eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c) eval_modulus(result, x, c); } +template +typename enable_if >::type eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c) +{ + if(b < 0) + { + BOOST_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent.")); + } + eval_powm(result, a, static_cast::type>(b), c); +} + template -void eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c) +typename enable_if >::type eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c) { typedef typename canonical::type ui_type; typedef typename canonical::type i1_type; @@ -354,11 +359,6 @@ void eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c) using default_ops::eval_modulus; using default_ops::eval_right_shift; - if(b < 0) - { - BOOST_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent.")); - } - Backend x, y(a); x = ui_type(1u); while(b > 0) @@ -375,6 +375,16 @@ void eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c) eval_modulus(result, x, static_cast(c)); } +template +typename enable_if >::type eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c) +{ + if(b < 0) + { + BOOST_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent.")); + } + eval_powm(result, a, static_cast::type>(b), c); +} + struct powm_func { template