Skip to content

Commit 827ee3b

Browse files
CopilotSimn
andcommitted
Fix bigint stdlib: change Vector<Int32> to Vector<Int>, shift params Int32→Int, tolerance UInt→Int
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
1 parent f177be2 commit 827ee3b

6 files changed

Lines changed: 36 additions & 36 deletions

File tree

std/haxe/math/bigint/BigInt.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ abstract BigInt(BigInt_) {
243243
@param tolerance The certainty level for the primality test.
244244
@return A probable prime `BigInt`.
245245
**/
246-
public static function randomPrime(bits:Int32, tolerance:UInt):BigInt {
246+
public static function randomPrime(bits:Int32, tolerance:Int):BigInt {
247247
return new BigInt(BigInt_.randomPrime(bits, tolerance));
248248
}
249249

@@ -334,7 +334,7 @@ abstract BigInt(BigInt_) {
334334
@param tolerance The certainty level. A higher value means a more rigorous (but slower) test.
335335
@return `true` if the number is probably prime, `false` if it is definitely composite.
336336
**/
337-
public function isProbablePrime(tolerance:UInt):Bool {
337+
public function isProbablePrime(tolerance:Int):Bool {
338338
return this.isProbablePrime(tolerance);
339339
}
340340

std/haxe/math/bigint/BigIntArithmetic.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ class BigIntArithmetic {
711711
//-----------------------------------------------------------------------
712712
// assumes 0 < shift < 32
713713
// ok if output == input
714-
private static inline function asl32(output:Vector<Int>, outputOffset:Int, input:Vector<Int>, inputSize:Int, shift:Int32):Void {
714+
private static inline function asl32(output:Vector<Int>, outputOffset:Int, input:Vector<Int>, inputSize:Int, shift:Int):Void {
715715
var x:Int = input.get(inputSize - 1) >> 31; // sign extend
716716
var r:Int = 32 - shift;
717717
var y:Int;
@@ -727,7 +727,7 @@ class BigIntArithmetic {
727727

728728
// assumes 0 < shift < 32
729729
// ok if output == input
730-
private static inline function lsl32(output:Vector<Int>, outputOffset:Int, input:Vector<Int>, inputSize:Int, shift:Int32):Void {
730+
private static inline function lsl32(output:Vector<Int>, outputOffset:Int, input:Vector<Int>, inputSize:Int, shift:Int):Void {
731731
var x:Int = 0;
732732
var r:Int = 32 - shift;
733733
var y:Int;
@@ -743,7 +743,7 @@ class BigIntArithmetic {
743743

744744
// assumes 0 < shift < 32
745745
// ok if output == input
746-
private static inline function lsr32(output:Vector<Int>, input:Vector<Int>, inputSize:Int, inputOffset:Int, shift:Int32):Void {
746+
private static inline function lsr32(output:Vector<Int>, input:Vector<Int>, inputSize:Int, inputOffset:Int, shift:Int):Void {
747747
var r:Int = 32 - shift;
748748
var i:Int = 0;
749749
while (i < inputSize - 1) {

std/haxe/math/bigint/BigInt_.hx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class BigInt_ {
699699
do {
700700
var bytes = randomBytes(bits);
701701
var excessBits = 8 * bytes.length - bits;
702-
bytes.set(0, bytes.get(0) | (1 << (7 - excessBits)));
702+
bytes.set(0, bytes.get(0) | (1 << (7 - (excessBits : Int))));
703703
bytes.set(bytes.length - 1, bytes.get(bytes.length - 1) | 1);
704704
r.setFromBigEndianBytesSigned(bytes);
705705
#if !cppia
@@ -803,7 +803,7 @@ class BigInt_ {
803803
}
804804

805805
#if neko
806-
private function millerRabin(rounds:UInt):Bool {
806+
private function millerRabin(rounds:Int):Bool {
807807
var minusOne:BigInt_ = subInt2(this, 1);
808808
var m = subInt2(this, 1);
809809
var lsb = m.getLowestSetBit();
@@ -934,13 +934,13 @@ class BigInt_ {
934934
j:Int;
935935
var smallMontyModulus:Bool;
936936
var mDash:Int32;
937-
var yAccum:Vector<Int32>,
938-
zVal:Vector<Int32>,
939-
tmp:Vector<Int32>,
940-
zSquared:Vector<Int32>,
941-
windowList:Vector<Int32>,
942-
yVal:Vector<Int32>;
943-
var oddPowers:Vector<Vector<Int32>>;
937+
var yAccum:Vector<Int>,
938+
zVal:Vector<Int>,
939+
tmp:Vector<Int>,
940+
zSquared:Vector<Int>,
941+
windowList:Vector<Int>,
942+
yVal:Vector<Int>;
943+
var oddPowers:Vector<Vector<Int>>;
944944
var m:BigInt_ = _m, e:BigInt_ = _e;
945945
n = m.m_count;
946946
powR = 32 * n;
@@ -949,11 +949,11 @@ class BigInt_ {
949949
if (convert) {
950950
b = divMod(BigInt_.arithmeticShiftLeft2(b, powR), m).remainder;
951951
}
952-
yAccum = new Vector<Int32>(n + 1);
952+
yAccum = new Vector<Int>(n + 1);
953953
zVal = b.m_data;
954954
var zLen = b.m_count;
955955
if (zLen < n) {
956-
tmp = new Vector<Int32>(n);
956+
tmp = new Vector<Int>(n);
957957
Vector.blit(zVal, 0, tmp, n - zLen, zLen);
958958
zVal = tmp;
959959
}
@@ -964,7 +964,7 @@ class BigInt_ {
964964
extraBits++;
965965
}
966966
numPowers = 1 << extraBits;
967-
oddPowers = new Vector<Vector<Int32>>(numPowers);
967+
oddPowers = new Vector<Vector<Int>>(numPowers);
968968
oddPowers[0] = zVal;
969969
zSquared = zVal.copy();
970970
squareMonty(yAccum, zSquared, m.m_data, m.m_count, mDash, smallMontyModulus);
@@ -1010,7 +1010,7 @@ class BigInt_ {
10101010
return montResult;
10111011
}
10121012

1013-
private function squareMonty(a:Vector<Int32>, x:Vector<Int32>, m:Vector<Int32>, mLen:Int, mDash:Int32, smallMontyModulus:Bool):Void {
1013+
private function squareMonty(a:Vector<Int>, x:Vector<Int>, m:Vector<Int>, mLen:Int, mDash:Int32, smallMontyModulus:Bool):Void {
10141014
var n:Int, aMax:Int, j:Int, i:Int;
10151015
var xVal:Int, a0:Int;
10161016
var x0:Int64, carry:Int64, t:Int64, prod1:Int64, prod2:Int64, xi:Int64, u:Int64;
@@ -1072,7 +1072,7 @@ class BigInt_ {
10721072
Vector.blit(a, 0, x, 0, n);
10731073
}
10741074

1075-
private function multiplyMonty(a:Vector<Int32>, x:Vector<Int32>, y:Vector<Int32>, m:Vector<Int32>, mLen:Int, mDash:Int32, smallMontyModulus:Bool):Void {
1075+
private function multiplyMonty(a:Vector<Int>, x:Vector<Int>, y:Vector<Int>, m:Vector<Int>, mLen:Int, mDash:Int32, smallMontyModulus:Bool):Void {
10761076
var n:Int, aMax:Int, j:Int, i:Int;
10771077
var a0:Int64, y0:Int64;
10781078
var carry:Int64, t:Int64, prod1:Int64, prod2:Int64, xi:Int64, u:Int64;
@@ -1114,7 +1114,7 @@ class BigInt_ {
11141114
Vector.blit(a, 0, x, 0, n);
11151115
}
11161116

1117-
private function montgomeryReduce(x:Vector<Int32>, m:Vector<Int32>, mLen:Int, mDash:Int32):Void {
1117+
private function montgomeryReduce(x:Vector<Int>, m:Vector<Int>, mLen:Int, mDash:Int32):Void {
11181118
var n:Int, i:Int, j:Int;
11191119
var x0:Int;
11201120
var t:Int64, carry:Int64;
@@ -1141,7 +1141,7 @@ class BigInt_ {
11411141
}
11421142

11431143
// x = x - y - where x is >= y
1144-
private function subtractMonty(x:Vector<Int32>,y:Vector<Int32>):Void {
1144+
private function subtractMonty(x:Vector<Int>,y:Vector<Int>):Void {
11451145
var yIndex:Int = y.length-1;
11461146
while(yIndex>=0 && y[yIndex]==0) {
11471147
yIndex--;
@@ -1159,7 +1159,7 @@ class BigInt_ {
11591159
}
11601160
}
11611161

1162-
private function compareMonty(x:Vector<Int32>, y:Vector<Int32>):Int {
1162+
private function compareMonty(x:Vector<Int>, y:Vector<Int>):Int {
11631163
var xIndex:Int = 0;
11641164
var yIndex:Int = 0;
11651165
var xLen:Int = x.length - 1;
@@ -1216,7 +1216,7 @@ class BigInt_ {
12161216
var e:BigInt_ = exponent;
12171217
var m:BigInt_ = modulus;
12181218
var oddPowers:Vector<BigInt_>;
1219-
var windowList:Vector<Int32>;
1219+
var windowList:Vector<Int>;
12201220

12211221
k = m.m_count;
12221222
mr = BigInt_.arithmeticShiftLeft2(BigInt.ONE, (k + 1) << 5);
@@ -1269,7 +1269,7 @@ class BigInt_ {
12691269
return y;
12701270
}
12711271

1272-
private function getWindowList(mag:Vector<Int32>, magLen:Int, extraBits:Int):Vector<Int32> {
1272+
private function getWindowList(mag:Vector<Int>, magLen:Int, extraBits:Int):Vector<Int> {
12731273
var i:Int,
12741274
v:Int32,
12751275
leadingBits:Int,
@@ -1282,7 +1282,7 @@ class BigInt_ {
12821282
v = mag[magLen - 1];
12831283
leadingBits = BigIntHelper.bitLen(v);
12841284
resultSize = Math.floor((((magLen - 1) << 5) + leadingBits) / (1 + extraBits) + 2);
1285-
var result:Vector<Int32> = new Vector<Int32>(resultSize);
1285+
var result:Vector<Int> = new Vector<Int>(resultSize);
12861286
resultPos = 0;
12871287
bitPos = 33 - leadingBits;
12881288
v = v << bitPos;

std/haxe/math/bigint/MultiwordArithmetic.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class MultiwordArithmetic {
338338
// special cases
339339
var dh:Int32 = divisor.get(divisorLength - 1);
340340
if (divisorLength < 2) {
341-
switch (dh) {
341+
switch ((dh : Int)) {
342342
case 0:
343343
throw new BigIntException(BigIntError.DIVISION_BY_ZERO);
344344
case 1:
@@ -747,10 +747,10 @@ class MultiwordArithmetic {
747747
@param radix The base for the conversion.
748748
@return The string representation.
749749
**/
750-
public static function toBaseString(value : Vector<Int32>, length : Int, radix:Int) : String
750+
public static function toBaseString(value : Vector<Int>, length : Int, radix:Int) : String
751751
{
752752
var sb = new StringBuf();
753-
var work = new Vector<Int32>(length);
753+
var work = new Vector<Int>(length);
754754
if (isNegative(value, length))
755755
{
756756
negate(work, value, length);
@@ -838,7 +838,7 @@ class MultiwordArithmetic {
838838

839839
// assumes 0 < shiftBits < 32
840840
// assumes shiftDigits < length
841-
private static function _asr32(result:Vector<Int>, input:Vector<Int>, length:Int, shiftDigits:Int, shiftBits:Int32):Void {
841+
private static function _asr32(result:Vector<Int>, input:Vector<Int>, length:Int, shiftDigits:Int, shiftBits:Int):Void {
842842
var r:Int = 32 - shiftBits;
843843
var i:Int = 0;
844844
while (i < length - shiftDigits - 1) {
@@ -850,7 +850,7 @@ class MultiwordArithmetic {
850850

851851
// assumes 0 < shift < 32
852852
// ok if output == input
853-
private static function _lsr32(output:Vector<Int>, input:Vector<Int>, inputSize:Int, inputOffset:Int, shift:Int32):Void {
853+
private static function _lsr32(output:Vector<Int>, input:Vector<Int>, inputSize:Int, inputOffset:Int, shift:Int):Void {
854854
var r:Int = 32 - shift;
855855
var i:Int = 0;
856856
while (i < inputSize - 1) {
@@ -866,11 +866,11 @@ class MultiwordArithmetic {
866866
}
867867

868868
@:noCompletion
869-
private static function _toBase(sb : StringBuf, value : Vector<Int32>, length : Int, radix:Int) : String
869+
private static function _toBase(sb : StringBuf, value : Vector<Int>, length : Int, radix:Int) : String
870870
{
871871
length = getLengthUnsigned(value, length);
872-
var digits = new Vector<Int32>(length * Math.ceil(Math.log(4294967296)/Math.log(radix)));
873-
var work = new Vector<Int32>(length + 1 + 1);
872+
var digits = new Vector<Int>(length * Math.ceil(Math.log(4294967296)/Math.log(radix)));
873+
var work = new Vector<Int>(length + 1 + 1);
874874
var pos : Int = digits.length;
875875
var r : Int;
876876
do

std/haxe/math/bigint/MutableBigInt.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ abstract MutableBigInt(MutableBigInt_) {
121121
@param sourcePosition The starting position in the source vector.
122122
@param length The number of words to copy.
123123
**/
124-
public inline function setFromVector(source : Vector<Int32>, sourcePosition:Int, length : Int ) : Void
124+
public inline function setFromVector(source : Vector<Int>, sourcePosition:Int, length : Int ) : Void
125125
{
126126
var a:MutableBigInt_ = this;
127127
a.setFromVector(source,sourcePosition, length);
@@ -238,7 +238,7 @@ abstract MutableBigInt(MutableBigInt_) {
238238
@param tolerance Certainty level for the Miller-Rabin test.
239239
@return `true` if probably prime.
240240
**/
241-
public function isProbablePrime(tolerance:UInt):Bool {
241+
public function isProbablePrime(tolerance:Int):Bool {
242242
return this.isProbablePrime(tolerance);
243243
}
244244

std/haxe/math/bigint/MutableBigInt_.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class MutableBigInt_ extends BigInt_ {
169169
@param sourcePosition The starting position in the source vector.
170170
@param length The number of words to copy.
171171
**/
172-
public function setFromVector(source : Vector<Int32>, sourcePosition:Int, length : Int ) : Void
172+
public function setFromVector(source : Vector<Int>, sourcePosition:Int, length : Int ) : Void
173173
{
174174
ensureCapacity(length , false);
175175
Vector.blit(source, sourcePosition, m_data, 0, length);

0 commit comments

Comments
 (0)