From 080f2bdfdc472c2c31f8c0ce881a84c63484c435 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Tue, 4 Dec 2018 11:27:37 -0700 Subject: [PATCH] Take care of the case where integer type Z has explicit constructor. --- include/boost/integer/mod_inverse.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/boost/integer/mod_inverse.hpp b/include/boost/integer/mod_inverse.hpp index d735d19..d57cbcc 100644 --- a/include/boost/integer/mod_inverse.hpp +++ b/include/boost/integer/mod_inverse.hpp @@ -22,24 +22,24 @@ namespace boost { namespace integer { template Z mod_inverse(Z a, Z modulus) { - if (modulus < 2) + if (modulus < Z(2)) { BOOST_THROW_EXCEPTION(std::domain_error("Modulus must be > 1.")); } // make sure a < modulus: a = a % modulus; - if (a == 0) + if (a == Z(0)) { // a doesn't have a modular multiplicative inverse: - return 0; + return Z(0); } euclidean_result_t u = extended_euclidean(a, modulus); - if (u.gcd > 1) + if (u.gcd > Z(1)) { - return 0; + return Z(0); } // x might not be in the range 0 < x < m, let's fix that: - while (u.x <= 0) + while (u.x <= Z(0)) { u.x += modulus; }