diff --git a/include/nil/crypto3/multiprecision/modular/modular_adaptor_fixed.hpp b/include/nil/crypto3/multiprecision/modular/modular_adaptor_fixed.hpp index c3bb2021..1853908a 100644 --- a/include/nil/crypto3/multiprecision/modular/modular_adaptor_fixed.hpp +++ b/include/nil/crypto3/multiprecision/modular/modular_adaptor_fixed.hpp @@ -14,7 +14,7 @@ #include #include -namespace boost { +namespace boost { namespace multiprecision { namespace backends { template @@ -80,9 +80,15 @@ namespace boost { template::value && std::is_signed::value> const * = nullptr> BOOST_MP_CXX14_CONSTEXPR modular_adaptor(SI b) - : m_base(b >= 0 ? - static_cast::type>(b) : - this->mod_data().get_mod() - static_cast::type>(-b) ) { + : m_base(static_cast::type>(0)) { + + if (b >= 0) { + m_base = static_cast::type>(b); + } else { + m_base = this->mod_data().get_mod(); + eval_subtract(m_base, static_cast::type>(-b) ); + } + // This method must be called only for compile time modular params. // this->set_modular_params(m); this->mod_data().adjust_modular(m_base); @@ -97,6 +103,22 @@ namespace boost { this->mod_data().adjust_modular(m_base); } + template::value && std::is_signed::value> const * = nullptr> + BOOST_MP_CXX14_CONSTEXPR modular_adaptor(SI b, const modular_type &m) + : m_base(static_cast::type>(0)) { + + if (b >= 0) { + m_base = static_cast::type>(b); + } else { + m_base = this->mod_data().get_mod(); + eval_subtract(m_base, static_cast::type>(-b)); + } + + this->set_modular_params(m); + this->mod_data().adjust_modular(m_base); + } + template::value && std::is_unsigned::value> const * = nullptr> BOOST_MP_CXX14_CONSTEXPR modular_adaptor(UI b, const modular_type &m)