Skip to content

Commit

Permalink
changing length to chunksLength in BigInt API
Browse files Browse the repository at this point in the history
  • Loading branch information
maitag committed Jul 4, 2022
1 parent 72a5b40 commit 42842d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/BigInt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ abstract BigInt(LittleIntChunks) from LittleIntChunks {
/**
return the number of chunks that is needed to store this BigInt
**/
public var length(get, never):Int;
public var chunksLength(get, never):Int;
inline function get_chunksLength():Int return (this == null) ? 0 : this.length;

var length(get, never):Int;
inline function get_length():Int return this.length;

/**
Expand Down Expand Up @@ -1084,7 +1087,7 @@ abstract BigInt(LittleIntChunks) from LittleIntChunks {
No support for handling negative params yet (like for two's complement behavior).
**/
@:op(A ^ B)
inline function opXOR(b:BigInt):BigInt {
function opXOR(b:BigInt):BigInt {
if (this == null) return b;
if (b == null) return this;
if (isNegative || b.isNegative) {
Expand All @@ -1106,7 +1109,7 @@ abstract BigInt(LittleIntChunks) from LittleIntChunks {
for (i in l...length) result.push(this.get(i));

result.truncateZeroChunks(true);
return result;
return (result.length == 0) ? null : result;
}
//@:op(A ^ B) @:commutative inline function opXORInt(b:Int):BigInt return opXOR(b);
@:op(A ^ B) static inline function opXORInt(a:Int, b:BigInt):BigInt return b.opXOR(a); // haxe 3.4.4 compatible!
Expand Down
5 changes: 3 additions & 2 deletions unit-tests/TestBigInt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -799,21 +799,22 @@ class TestBigInt extends haxe.unit.TestCase
assertTrue(("0b 11010110" : BigInt) & ("0b 00000000" : BigInt) == 0);
assertTrue(("0b 11100101101111100010010100011001110010110100111001001111011100011100011101001" : BigInt) & ("0b 1101" : BigInt) == ("0b 1001" : BigInt));
assertTrue(("0b 1101" : BigInt) & ("0b 11100101101111100010010100011001110010110100111001001111011100011100011101001" : BigInt) == ("0b 1001" : BigInt));

assertTrue((("0b 1101" : BigInt) & ("0b 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111100 11100101 11001110 10111001 11010010" : BigInt)).isZero);

assertTrue(("0b 00000000" : BigInt) | ("0b 00000000" : BigInt) == ("0b 00000000" : BigInt));
assertTrue(("0b 00000000" : BigInt) | ("0b 01010111" : BigInt) == ("0b 01010111" : BigInt));
assertTrue(("0b 11010110" : BigInt) | ("0b 00000000" : BigInt) == ("0b 11010110" : BigInt));
assertTrue(("0b 11100101101111100010010100011001110010110100111001001111011100011100011101001" : BigInt) | ("0b 1101" : BigInt) == ("0b 11100101101111100010010100011001110010110100111001001111011100011100011101101" : BigInt));
assertTrue(("0b 1101" : BigInt) | ("0b 11100101101111100010010100011001110010110100111001001111011100011100011101001" : BigInt) == ("0b 11100101101111100010010100011001110010110100111001001111011100011100011101101" : BigInt));


assertTrue(("0b 00000000" : BigInt) ^ ("0b 00000000" : BigInt) == ("0b 00000000" : BigInt));
assertTrue(("0b 00000000" : BigInt) ^ ("0b 11010110" : BigInt) == ("0b 11010110" : BigInt));
assertTrue(("0b 01010110" : BigInt) ^ ("0b 00000000" : BigInt) == ("0b 01010110" : BigInt));
assertTrue(("0b 11010110" : BigInt) ^ ("0b 01010101" : BigInt) == ("0b 10000011" : BigInt));
assertTrue(("0b 111111110011100101110011101011100111010111" : BigInt) ^ ("0b 101" : BigInt) == ("0b 111111110011100101110011101011100111010010" : BigInt));
assertTrue(("0b 1001" : BigInt) ^ ("0b 11001011100011110110101110101000100111001110011111101111101111" : BigInt) == ("0b 11001011100011110110101110101000100111001110011111101111100110" : BigInt));
assertTrue((("0b 11001011100011110110101110101000100111001110011111101111101111" : BigInt) ^ ("0b 11001011100011110110101110101000100111001110011111101111101111" : BigInt)).isZero);
assertTrue((("0b 11001011100011110110101110101000100111001110011111101111101110" : BigInt) ^ ("0b 11001011100011110110101110101000100111001110011111101111101111" : BigInt)).chunksLength == 1);
}

public function testBitwiseWithInts() {
Expand Down

0 comments on commit 42842d6

Please sign in to comment.