mhogrefe / malachite

An arbitrary-precision arithmetic library for Rust.
GNU Lesser General Public License v3.0
448 stars 17 forks source link

Incorrect ModPow implement for Natural #19

Closed qingshi163 closed 1 year ago

qingshi163 commented 1 year ago

the match arm inside mod_pow function (x, naturalone!(), ) will return x.clone() but is not correct if the modulus smaller than x. it should return the modulus - 1 instead x.

mhogrefe commented 1 year ago

Thanks for your comment. All of the mod_ functions assume that their input is already reduced, so the modulus should never be smaller than x. This is mentioned in the documentation for each function, but I will consider adding a runtime check (which wouldn't take too much time).

qingshi163 commented 1 year ago

Sorry did not see that, maybe a debug_assert will be great!