Skip to content

Commit

Permalink
Merge pull request #15 from cjpatton/faster-pow
Browse files Browse the repository at this point in the history
fp: Remove no-op multiplications from FieldParameters::pow
  • Loading branch information
tgeoghegan authored Mar 26, 2021
2 parents b6dffc6 + cfd5330 commit 56c194a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl FieldParameters {
/// runtime of this algorithm is linear in the bit length of `exp`.
pub fn pow(&self, x: u128, exp: u128) -> u128 {
let mut t = self.elem(1);
for i in (0..128).rev() {
for i in (0..128 - exp.leading_zeros()).rev() {
t = self.mul(t, t);
if (exp >> i) & 1 != 0 {
t = self.mul(t, x);
Expand Down

0 comments on commit 56c194a

Please sign in to comment.