mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
math.big: fix the order of calculations in mod_pow() to improve performance (#24935)
This commit is contained in:
parent
e3d047822d
commit
987c211517
1 changed files with 2 additions and 2 deletions
|
@ -605,9 +605,9 @@ pub fn (base Integer) mod_pow(exponent u32, modulus Integer) Integer {
|
||||||
mut y := one_int
|
mut y := one_int
|
||||||
for n > 1 {
|
for n > 1 {
|
||||||
if n & 1 == 1 {
|
if n & 1 == 1 {
|
||||||
y *= x % modulus
|
y = (y * x) % modulus
|
||||||
}
|
}
|
||||||
x *= x % modulus
|
x = (x * x) % modulus
|
||||||
n >>= 1
|
n >>= 1
|
||||||
}
|
}
|
||||||
return x * y % modulus
|
return x * y % modulus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue