mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
llModPow precision has been fixed and the delay removed
This commit is contained in:
parent
e27ece3536
commit
23e71354c5
6 changed files with 34 additions and 44 deletions
|
@ -1797,15 +1797,9 @@ def llModPow(base, exp, mod):
|
|||
base = fi(base)
|
||||
exp = fi(exp)
|
||||
mod = fi(mod)
|
||||
if not lslcommon.IsCalc:
|
||||
# This function has a delay, therefore it's not safe to compute it
|
||||
# unless in calculator mode.
|
||||
raise ELSLCantCompute
|
||||
# With some luck, this works fully with native ints on 64 bit machines.
|
||||
if mod in (0, 1):
|
||||
return 0
|
||||
if exp == 0:
|
||||
return 1
|
||||
# Convert all numbers to unsigned
|
||||
base &= 0xFFFFFFFF
|
||||
exp &= 0xFFFFFFFF
|
||||
|
@ -1814,11 +1808,11 @@ def llModPow(base, exp, mod):
|
|||
ret = 1
|
||||
while True:
|
||||
if exp & 1:
|
||||
ret = ((ret * prod) & 0xFFFFFFFF) % mod
|
||||
ret = ((ret * prod) % mod) & 0xFFFFFFFF
|
||||
exp = exp >> 1
|
||||
if exp == 0:
|
||||
break
|
||||
prod = ((prod * prod) & 0xFFFFFFFF) % mod
|
||||
prod = ((prod * prod) % mod) & 0xFFFFFFFF
|
||||
|
||||
return S32(ret)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue