From 7778f199e883f8b49622c63933dd984220b45c97 Mon Sep 17 00:00:00 2001 From: flashultra Date: Thu, 19 Dec 2024 19:20:36 +0200 Subject: [PATCH] Fix for Neko --- std/haxe/math/bigint/BigInt_.hx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/std/haxe/math/bigint/BigInt_.hx b/std/haxe/math/bigint/BigInt_.hx index 2a40c66cfc0..b1c7caa989e 100644 --- a/std/haxe/math/bigint/BigInt_.hx +++ b/std/haxe/math/bigint/BigInt_.hx @@ -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; @@ -422,6 +441,7 @@ class BigInt_ { } return result; } + #end public function pow(exponent:UInt):BigInt_ { if (exponent < 0)