Skip to content

Commit

Permalink
Fix for Neko
Browse files Browse the repository at this point in the history
  • Loading branch information
flashultra committed Dec 19, 2024
1 parent 428232e commit 7778f19
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions std/haxe/math/bigint/BigInt_.hx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,25 @@ class BigInt_ {
return r;
}

#if neko
public function modPow(exponent:BigInt_, modulus:BigInt_):BigInt_ {
if (BigIntArithmetic.compareInt(exponent, 0) < 0)
throw new BigIntException(BigIntError.NEGATIVE_EXPONENT);
if (this.isZero())
return (BigIntArithmetic.compareInt(exponent, 0) == 0 ? BigInt.fromInt(1) : this);
var r = BigInt_.newFromInt(1);
var p:BigInt_ = this;
while (true) {
if (BigIntArithmetic.bitwiseAndInt(exponent, 1) == 1)
r = modulus2(multiply2(p, r), modulus);
exponent = BigInt_.arithmeticShiftRight2(exponent, 1);
if (BigIntArithmetic.compareInt(exponent, 0) == 0)
break;
p = modulus2(multiply2(p, p), modulus);
}
return r;
}
#else
public function modPow(exponent:BigInt_, modulus:BigInt_):BigInt_ {
if (BigIntArithmetic.compareInt(modulus, 0) < 0)
throw BigIntError.NEGATIVE_MODULUS;
Expand All @@ -422,6 +441,7 @@ class BigInt_ {
}
return result;
}
#end

public function pow(exponent:UInt):BigInt_ {
if (exponent < 0)
Expand Down

0 comments on commit 7778f19

Please sign in to comment.