@oathompsonjones/mini-games 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/lint-and-test.yml +52 -0
- package/.github/workflows/publish.yml +36 -0
- package/build/base/board.d.ts +17 -58
- package/build/base/board.js +23 -75
- package/build/base/controller.d.ts +16 -34
- package/build/base/controller.js +27 -39
- package/build/bitBoard/bitBoard.d.ts +8 -33
- package/build/bitBoard/bitBoard.js +7 -12
- package/build/bitBoard/intBitBoard.d.ts +65 -4
- package/build/bitBoard/intBitBoard.js +66 -5
- package/build/bitBoard/longInt.d.ts +2 -32
- package/build/bitBoard/longInt.js +17 -25
- package/build/bitBoard/longIntBitBoard.d.ts +65 -7
- package/build/bitBoard/longIntBitBoard.js +72 -4
- package/build/console.d.ts +1 -4
- package/build/console.js +4 -7
- package/build/games/connect4/board.d.ts +9 -0
- package/build/games/connect4/board.js +10 -1
- package/build/games/connect4/controller.d.ts +18 -0
- package/build/games/connect4/controller.js +23 -1
- package/build/games/tictactoe/board.d.ts +3 -0
- package/build/games/tictactoe/board.js +4 -1
- package/build/games/tictactoe/controller.d.ts +20 -0
- package/build/games/tictactoe/controller.js +25 -1
- package/build/index.js +1 -1
- package/eslint.config.js +3 -0
- package/package.json +6 -8
- package/.eslintrc +0 -6
|
@@ -1,27 +1,88 @@
|
|
|
1
1
|
import BitBoard from "./bitBoard.js";
|
|
2
|
-
/**
|
|
3
|
-
* Represents a BitBoard which uses just one 32-bit number.
|
|
4
|
-
*/
|
|
2
|
+
/** Represents a BitBoard which uses just one 32-bit number. */
|
|
5
3
|
export default class IntBitBoard extends BitBoard<number> {
|
|
6
4
|
/**
|
|
7
5
|
* Creates an instance of NumberBitBoard.
|
|
8
|
-
*
|
|
9
6
|
* @param data The data to fill the BitBoard with.
|
|
10
7
|
*/
|
|
11
8
|
constructor(data?: number);
|
|
9
|
+
/**
|
|
10
|
+
* Gets the value of a given bit.
|
|
11
|
+
* @param bit The bit to get.
|
|
12
|
+
* @returns The value of the bit.
|
|
13
|
+
*/
|
|
12
14
|
getBit(bit: number): 0 | 1;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the value for a given bit to 1.
|
|
17
|
+
* @param bit The bit to set.
|
|
18
|
+
*/
|
|
13
19
|
setBit(bit: number): void;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the value for a given bit to 0.
|
|
22
|
+
* @param bit The bit to clear.
|
|
23
|
+
*/
|
|
14
24
|
clearBit(bit: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Toggles the data for a given bit between 0 and 1.
|
|
27
|
+
* @param bit The bit to toggle.
|
|
28
|
+
*/
|
|
15
29
|
toggleBit(bit: number): void;
|
|
30
|
+
/** Sets all bits to 0. */
|
|
16
31
|
clearAll(): void;
|
|
32
|
+
/** Sets all bits to 1. */
|
|
17
33
|
setAll(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Gets a given number of bits.
|
|
36
|
+
* @param LSB The least significant bit to get.
|
|
37
|
+
* @param numberOfBits The number of bits to get.
|
|
38
|
+
* @returns The bits.
|
|
39
|
+
*/
|
|
18
40
|
getBits(LSB: number, numberOfBits: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Carries out an in-place bitwise and (&) operation on this board and the one provided.
|
|
43
|
+
* @param right The other bitboard.
|
|
44
|
+
* @returns The result of the operation.
|
|
45
|
+
*/
|
|
19
46
|
and(right: IntBitBoard | number): this;
|
|
47
|
+
/**
|
|
48
|
+
* Carries out an in-place bitwise or (|) operation on this board and the one provided.
|
|
49
|
+
* @param right The other bitboard.
|
|
50
|
+
* @returns The result of the operation.
|
|
51
|
+
*/
|
|
20
52
|
or(right: IntBitBoard | number): this;
|
|
53
|
+
/**
|
|
54
|
+
* Carries out an in-place bitwise xor (^) operation on this board and the one provided.
|
|
55
|
+
* @param right The other bitboard.
|
|
56
|
+
* @returns The result of the operation.
|
|
57
|
+
*/
|
|
21
58
|
xor(right: IntBitBoard | number): this;
|
|
59
|
+
/**
|
|
60
|
+
* Carries out an in-place bitwise not (~) operation on this board.
|
|
61
|
+
* @returns The result of the operation.
|
|
62
|
+
*/
|
|
22
63
|
not(): this;
|
|
64
|
+
/**
|
|
65
|
+
* Carries out an in-place bitwise left shift (<<) operation on this board.
|
|
66
|
+
* @param shiftAmount The amount to shift by.
|
|
67
|
+
* @returns The result of the operation.
|
|
68
|
+
*/
|
|
23
69
|
leftShift(shiftAmount: number): this;
|
|
70
|
+
/**
|
|
71
|
+
* Carries out an in-place bitwise unsigned right shift (>>>) operation on this board.
|
|
72
|
+
* @param shiftAmount The amount to shift by.
|
|
73
|
+
* @returns The result of the operation.
|
|
74
|
+
*/
|
|
24
75
|
rightShift(shiftAmount: number): this;
|
|
76
|
+
/**
|
|
77
|
+
* Carries out an in-place bitwise arithmetic right shift (>>) operation on this board.
|
|
78
|
+
* @param shiftAmount The amount to shift by.
|
|
79
|
+
* @returns The result of the operation.
|
|
80
|
+
*/
|
|
25
81
|
arithmeticRightShift(shiftAmount: number): this;
|
|
82
|
+
/**
|
|
83
|
+
* Checks if the current bitboard is equal to another.
|
|
84
|
+
* @param value The other bitboard.
|
|
85
|
+
* @returns Whether or not the bitboards are equal.
|
|
86
|
+
*/
|
|
26
87
|
equals(value: IntBitBoard | number): boolean;
|
|
27
88
|
}
|
|
@@ -1,65 +1,126 @@
|
|
|
1
1
|
import BitBoard from "./bitBoard.js";
|
|
2
|
-
/**
|
|
3
|
-
* Represents a BitBoard which uses just one 32-bit number.
|
|
4
|
-
*/
|
|
2
|
+
/** Represents a BitBoard which uses just one 32-bit number. */
|
|
5
3
|
export default class IntBitBoard extends BitBoard {
|
|
6
4
|
/**
|
|
7
5
|
* Creates an instance of NumberBitBoard.
|
|
8
|
-
*
|
|
9
6
|
* @param data The data to fill the BitBoard with.
|
|
10
7
|
*/
|
|
11
8
|
constructor(data = 0) {
|
|
12
9
|
super(data);
|
|
13
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Gets the value of a given bit.
|
|
13
|
+
* @param bit The bit to get.
|
|
14
|
+
* @returns The value of the bit.
|
|
15
|
+
*/
|
|
14
16
|
getBit(bit) {
|
|
15
17
|
return (this._data >>> bit & 1);
|
|
16
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Sets the value for a given bit to 1.
|
|
21
|
+
* @param bit The bit to set.
|
|
22
|
+
*/
|
|
17
23
|
setBit(bit) {
|
|
18
24
|
const mask = 1 << bit;
|
|
19
25
|
this._data |= mask;
|
|
20
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Sets the value for a given bit to 0.
|
|
29
|
+
* @param bit The bit to clear.
|
|
30
|
+
*/
|
|
21
31
|
clearBit(bit) {
|
|
22
32
|
const mask = ~(1 << bit);
|
|
23
33
|
this._data &= mask;
|
|
24
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Toggles the data for a given bit between 0 and 1.
|
|
37
|
+
* @param bit The bit to toggle.
|
|
38
|
+
*/
|
|
25
39
|
toggleBit(bit) {
|
|
26
40
|
const mask = 1 << bit;
|
|
27
41
|
this._data ^= mask;
|
|
28
42
|
}
|
|
43
|
+
/** Sets all bits to 0. */
|
|
29
44
|
clearAll() {
|
|
30
45
|
this._data = 0;
|
|
31
46
|
}
|
|
47
|
+
/** Sets all bits to 1. */
|
|
32
48
|
setAll() {
|
|
33
49
|
this._data = ~0 >>> 0;
|
|
34
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets a given number of bits.
|
|
53
|
+
* @param LSB The least significant bit to get.
|
|
54
|
+
* @param numberOfBits The number of bits to get.
|
|
55
|
+
* @returns The bits.
|
|
56
|
+
*/
|
|
35
57
|
getBits(LSB, numberOfBits) {
|
|
36
58
|
const mask = 2 ** numberOfBits - 1 << LSB;
|
|
37
59
|
const bits = (this._data & mask) >>> LSB;
|
|
38
60
|
return bits;
|
|
39
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Carries out an in-place bitwise and (&) operation on this board and the one provided.
|
|
64
|
+
* @param right The other bitboard.
|
|
65
|
+
* @returns The result of the operation.
|
|
66
|
+
*/
|
|
40
67
|
and(right) {
|
|
41
68
|
return new IntBitBoard(this._data & (right instanceof IntBitBoard ? right.data : right));
|
|
42
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Carries out an in-place bitwise or (|) operation on this board and the one provided.
|
|
72
|
+
* @param right The other bitboard.
|
|
73
|
+
* @returns The result of the operation.
|
|
74
|
+
*/
|
|
43
75
|
or(right) {
|
|
44
76
|
return new IntBitBoard(this._data | (right instanceof IntBitBoard ? right.data : right));
|
|
45
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Carries out an in-place bitwise xor (^) operation on this board and the one provided.
|
|
80
|
+
* @param right The other bitboard.
|
|
81
|
+
* @returns The result of the operation.
|
|
82
|
+
*/
|
|
46
83
|
xor(right) {
|
|
47
84
|
return new IntBitBoard(this._data ^ (right instanceof IntBitBoard ? right.data : right));
|
|
48
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Carries out an in-place bitwise not (~) operation on this board.
|
|
88
|
+
* @returns The result of the operation.
|
|
89
|
+
*/
|
|
49
90
|
not() {
|
|
50
91
|
return new IntBitBoard(~this._data);
|
|
51
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Carries out an in-place bitwise left shift (<<) operation on this board.
|
|
95
|
+
* @param shiftAmount The amount to shift by.
|
|
96
|
+
* @returns The result of the operation.
|
|
97
|
+
*/
|
|
52
98
|
leftShift(shiftAmount) {
|
|
53
99
|
return new IntBitBoard(this._data << shiftAmount);
|
|
54
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Carries out an in-place bitwise unsigned right shift (>>>) operation on this board.
|
|
103
|
+
* @param shiftAmount The amount to shift by.
|
|
104
|
+
* @returns The result of the operation.
|
|
105
|
+
*/
|
|
55
106
|
rightShift(shiftAmount) {
|
|
56
107
|
return new IntBitBoard(this._data >>> shiftAmount);
|
|
57
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Carries out an in-place bitwise arithmetic right shift (>>) operation on this board.
|
|
111
|
+
* @param shiftAmount The amount to shift by.
|
|
112
|
+
* @returns The result of the operation.
|
|
113
|
+
*/
|
|
58
114
|
arithmeticRightShift(shiftAmount) {
|
|
59
115
|
return new IntBitBoard(this._data >> shiftAmount);
|
|
60
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Checks if the current bitboard is equal to another.
|
|
119
|
+
* @param value The other bitboard.
|
|
120
|
+
* @returns Whether or not the bitboards are equal.
|
|
121
|
+
*/
|
|
61
122
|
equals(value) {
|
|
62
123
|
return this._data === (value instanceof IntBitBoard ? value._data : value);
|
|
63
124
|
}
|
|
64
125
|
}
|
|
65
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
126
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50Qml0Qm9hcmQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYml0Qm9hcmQvaW50Qml0Qm9hcmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxRQUFRLE1BQU0sZUFBZSxDQUFDO0FBRXJDLCtEQUErRDtBQUMvRCxNQUFNLENBQUMsT0FBTyxPQUFPLFdBQVksU0FBUSxRQUFnQjtJQUNyRDs7O09BR0c7SUFDSCxZQUFtQixPQUFlLENBQUM7UUFDL0IsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ2hCLENBQUM7SUFFRDs7OztPQUlHO0lBQ0ksTUFBTSxDQUFDLEdBQVc7UUFDckIsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLEtBQUssR0FBRyxHQUFHLENBQUMsQ0FBVSxDQUFDO0lBQzdDLENBQUM7SUFFRDs7O09BR0c7SUFDSSxNQUFNLENBQUMsR0FBVztRQUNyQixNQUFNLElBQUksR0FBRyxDQUFDLElBQUksR0FBRyxDQUFDO1FBRXRCLElBQUksQ0FBQyxLQUFLLEl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24gdGhpcyBib2FyZC5cbiAgICAgKiBAcGFyYW0gc2hpZnRBbW91bnQgVGhlIGFtb3VudCB0byBzaGlmdCBieS5cbiAgICAgKiBAcmV0dXJucyBUaGUgcmVzdWx0IG9mIHRoZSBvcGVyYXRpb24uXG4gICAgICovXG4gICAgcHVibGljIGFyaXRobWV0aWNSaWdodFNoaWZ0KHNoaWZ0QW1vdW50OiBudW1iZXIpOiB0aGlzIHtcbiAgICAgICAgcmV0dXJuIG5ldyBJbnRCaXRCb2FyZCh0aGlzLl9kYXRhID4+IHNoaWZ0QW1vdW50KSBhcyB0aGlzO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIENoZWNrcyBpZiB0aGUgY3VycmVudCBiaXRib2FyZCBpcyBlcXVhbCB0byBhbm90aGVyLlxuICAgICAqIEBwYXJhbSB2YWx1ZSBUaGUgb3RoZXIgYml0Ym9hcmQuXG4gICAgICogQHJldHVybnMgV2hldGhlciBvciBub3QgdGhlIGJpdGJvYXJkcyBhcmUgZXF1YWwuXG4gICAgICovXG4gICAgcHVibGljIGVxdWFscyh2YWx1ZTogSW50Qml0Qm9hcmQgfCBudW1iZXIpOiBib29sZWFuIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2RhdGEgPT09ICh2YWx1ZSBpbnN0YW5jZW9mIEludEJpdEJvYXJkID8gdmFsdWUuX2RhdGEgOiB2YWx1ZSk7XG4gICAgfVxufVxuIl19
|
|
@@ -5,35 +5,27 @@
|
|
|
5
5
|
* Provides non-static equivalents to the above operations, which are carried out in place.
|
|
6
6
|
*/
|
|
7
7
|
export default class LongInt {
|
|
8
|
-
/**
|
|
9
|
-
* Holds the array of 32-bit numbers.
|
|
10
|
-
*/
|
|
8
|
+
/** Holds the array of 32-bit numbers. */
|
|
11
9
|
readonly data: Uint32Array;
|
|
12
10
|
/**
|
|
13
11
|
* Creates an instance of LongInt.
|
|
14
|
-
*
|
|
15
12
|
* @param values A little-endian array of 32-bit numbers to fill the `LongInt`.
|
|
16
13
|
*/
|
|
17
14
|
constructor(values: number[] | Uint32Array);
|
|
18
15
|
/**
|
|
19
16
|
* Creates an instance of LongInt.
|
|
20
|
-
*
|
|
21
17
|
* @param length The number of 32-bit numbers to construct the `LongInt` out of.
|
|
22
18
|
*/
|
|
23
19
|
constructor(length: number);
|
|
24
20
|
/**
|
|
25
21
|
* Creates an instance of LongInt.
|
|
26
|
-
*
|
|
27
22
|
* @param longInt A `LongInt` object to duplicate.
|
|
28
23
|
*/
|
|
29
24
|
constructor(longInt: LongInt);
|
|
30
|
-
/**
|
|
31
|
-
* Gets the number of 32-bit words which make the LongInt.
|
|
32
|
-
*/
|
|
25
|
+
/** Gets the number of 32-bit words which make the LongInt. */
|
|
33
26
|
get wordCount(): number;
|
|
34
27
|
/**
|
|
35
28
|
* Carries out a bitwise and (&) operation on the two numbers.
|
|
36
|
-
*
|
|
37
29
|
* @param left The left number.
|
|
38
30
|
* @param right The right number.
|
|
39
31
|
* @returns The result of left & right.
|
|
@@ -41,7 +33,6 @@ export default class LongInt {
|
|
|
41
33
|
static and(left: LongInt, right: LongInt | number): LongInt;
|
|
42
34
|
/**
|
|
43
35
|
* Carries out a bitwise or (|) operation on the two numbers.
|
|
44
|
-
*
|
|
45
36
|
* @param left The left number.
|
|
46
37
|
* @param right The right number.
|
|
47
38
|
* @returns The result of left | right.
|
|
@@ -49,7 +40,6 @@ export default class LongInt {
|
|
|
49
40
|
static or(left: LongInt, right: LongInt | number): LongInt;
|
|
50
41
|
/**
|
|
51
42
|
* Carries out a bitwise xor (^) operation on the two numbers.
|
|
52
|
-
*
|
|
53
43
|
* @param left The left number.
|
|
54
44
|
* @param right The right number.
|
|
55
45
|
* @returns The result of left ^ right.
|
|
@@ -57,14 +47,12 @@ export default class LongInt {
|
|
|
57
47
|
static xor(left: LongInt, right: LongInt | number): LongInt;
|
|
58
48
|
/**
|
|
59
49
|
* Carries out a bitwise not (~) operation on the number.
|
|
60
|
-
*
|
|
61
50
|
* @param number The number to negate.
|
|
62
51
|
* @returns The result of ~number.
|
|
63
52
|
*/
|
|
64
53
|
static not(number: LongInt): LongInt;
|
|
65
54
|
/**
|
|
66
55
|
* Carries out a bitwise left shift (<<) operation on the number.
|
|
67
|
-
*
|
|
68
56
|
* @param number The number to shift.
|
|
69
57
|
* @param shiftAmount The number of places to shift.
|
|
70
58
|
* @returns The result of number << shiftAmount.
|
|
@@ -72,7 +60,6 @@ export default class LongInt {
|
|
|
72
60
|
static leftShift(number: LongInt, shiftAmount: number): LongInt;
|
|
73
61
|
/**
|
|
74
62
|
* Carries out a bitwise unsigned right shift (>>>) operation on the number.
|
|
75
|
-
*
|
|
76
63
|
* @param number The number to shift.
|
|
77
64
|
* @param shiftAmount The number of places to shift.
|
|
78
65
|
* @returns The result of number >>> shiftAmount.
|
|
@@ -80,7 +67,6 @@ export default class LongInt {
|
|
|
80
67
|
static rightShift(number: LongInt, shiftAmount: number): LongInt;
|
|
81
68
|
/**
|
|
82
69
|
* Carries out a bitwise arithmetic right shift (>>) operation on the number.
|
|
83
|
-
*
|
|
84
70
|
* @param number The number to shift.
|
|
85
71
|
* @param shiftAmount The number of places to shift.
|
|
86
72
|
* @returns The result of number >> shiftAmount.
|
|
@@ -88,7 +74,6 @@ export default class LongInt {
|
|
|
88
74
|
static arithmeticRightShift(number: LongInt, shiftAmount: number): LongInt;
|
|
89
75
|
/**
|
|
90
76
|
* Determines whether or not 2 LongInts have equal values.
|
|
91
|
-
*
|
|
92
77
|
* @param longInt1 The first LongInt.
|
|
93
78
|
* @param longInt2 The second LongInt (can also be a number).
|
|
94
79
|
* @returns Whether or not they are equal.
|
|
@@ -96,7 +81,6 @@ export default class LongInt {
|
|
|
96
81
|
static equals(longInt1: LongInt, longInt2: LongInt | number): boolean;
|
|
97
82
|
/**
|
|
98
83
|
* Creates a new LongInt object with the given value, stretched or truncated to the same size as this.
|
|
99
|
-
*
|
|
100
84
|
* @param longInt The LongInt to match the dimensions of.
|
|
101
85
|
* @param value The LongInt object to use as the value.
|
|
102
86
|
* @returns The new LongInt.
|
|
@@ -104,7 +88,6 @@ export default class LongInt {
|
|
|
104
88
|
static getMatchingLongInt(longInt: LongInt, value: LongInt): LongInt;
|
|
105
89
|
/**
|
|
106
90
|
* Creates a new LongInt object using the given value, stretched or truncated to the same size as this.
|
|
107
|
-
*
|
|
108
91
|
* @param longInt The LongInt to match the dimensions of.
|
|
109
92
|
* @param values An array of 32-bit numbers to use as the value.
|
|
110
93
|
* @returns The new LongInt.
|
|
@@ -112,7 +95,6 @@ export default class LongInt {
|
|
|
112
95
|
static getMatchingLongInt(longInt: LongInt, values: number[] | Uint32Array): LongInt;
|
|
113
96
|
/**
|
|
114
97
|
* Creates a new LongInt object using the given value, stretched or truncated to the same size as this.
|
|
115
|
-
*
|
|
116
98
|
* @param longInt The LongInt to match the dimensions of.
|
|
117
99
|
* @param value A 32-bit number to use as the value.
|
|
118
100
|
* @returns The new LongInt.
|
|
@@ -120,76 +102,65 @@ export default class LongInt {
|
|
|
120
102
|
static getMatchingLongInt(longInt: LongInt, value?: number): LongInt;
|
|
121
103
|
/**
|
|
122
104
|
* Carries out an in-place bitwise and (&) operation on this number and the one provided.
|
|
123
|
-
*
|
|
124
105
|
* @param right The right number.
|
|
125
106
|
* @returns The new value of this & right.
|
|
126
107
|
*/
|
|
127
108
|
and(right: LongInt | number): this;
|
|
128
109
|
/**
|
|
129
110
|
* Carries out an in-place bitwise or (|) operation on this number and the one provided.
|
|
130
|
-
*
|
|
131
111
|
* @param right The right number.
|
|
132
112
|
* @returns The new value of this | right.
|
|
133
113
|
*/
|
|
134
114
|
or(right: LongInt | number): this;
|
|
135
115
|
/**
|
|
136
116
|
* Carries out an in-place bitwise xor (^) operation on this number and the one provided.
|
|
137
|
-
*
|
|
138
117
|
* @param right The right number.
|
|
139
118
|
* @returns The new value of this ^ right.
|
|
140
119
|
*/
|
|
141
120
|
xor(right: LongInt | number): this;
|
|
142
121
|
/**
|
|
143
122
|
* Carries out an in-place bitwise not (~) operation on this nurmbe.
|
|
144
|
-
*
|
|
145
123
|
* @returns The result of ~this.
|
|
146
124
|
*/
|
|
147
125
|
not(): this;
|
|
148
126
|
/**
|
|
149
127
|
* Carries out an in-place bitwise left shift (<<) operation on this number.
|
|
150
|
-
*
|
|
151
128
|
* @param shiftAmount The number of places to shift.
|
|
152
129
|
* @returns The result of this << shiftAmount.
|
|
153
130
|
*/
|
|
154
131
|
leftShift(shiftAmount: number): this;
|
|
155
132
|
/**
|
|
156
133
|
* Carries out an in-place bitwise unsigned right shift (>>>) operation on this number.
|
|
157
|
-
*
|
|
158
134
|
* @param shiftAmount The number of places to shift.
|
|
159
135
|
* @returns The result of this >>> shiftAmount.
|
|
160
136
|
*/
|
|
161
137
|
rightShift(shiftAmount: number): this;
|
|
162
138
|
/**
|
|
163
139
|
* Carries out an in-place bitwise arithmetic right shift (>>) operation on this number.
|
|
164
|
-
*
|
|
165
140
|
* @param shiftAmount The number of places to shift.
|
|
166
141
|
* @returns The result of this >> shiftAmount.
|
|
167
142
|
*/
|
|
168
143
|
arithmeticRightShift(shiftAmount: number): this;
|
|
169
144
|
/**
|
|
170
145
|
* Determines whether or not this LongInt has equal value to another.
|
|
171
|
-
*
|
|
172
146
|
* @param value The LongInt or number to compare to.
|
|
173
147
|
* @returns Whether or not they are equal.
|
|
174
148
|
*/
|
|
175
149
|
equals(value: LongInt | number): boolean;
|
|
176
150
|
/**
|
|
177
151
|
* Returns a string representation of the LongInt.
|
|
178
|
-
*
|
|
179
152
|
* @param type The base of the string to print.
|
|
180
153
|
* @returns The string representation.
|
|
181
154
|
*/
|
|
182
155
|
toString(type: StringType): string;
|
|
183
156
|
/**
|
|
184
157
|
* Creates a new LongInt object with the given value, stretched or truncated to the same size as this.
|
|
185
|
-
*
|
|
186
158
|
* @param longInt The LongInt object to use as the value.
|
|
187
159
|
* @returns The new LongInt.
|
|
188
160
|
*/
|
|
189
161
|
private getMatchingLongInt;
|
|
190
162
|
/**
|
|
191
163
|
* Shifts the 32-bit number array to the right.
|
|
192
|
-
*
|
|
193
164
|
* @param count How many places to shift the array.
|
|
194
165
|
* @param fillValue The value to fill empty spaces with.
|
|
195
166
|
* @returns The new value of this.
|
|
@@ -197,7 +168,6 @@ export default class LongInt {
|
|
|
197
168
|
private shiftArrayRight;
|
|
198
169
|
/**
|
|
199
170
|
* Shifts the 32-bit number array to the left.
|
|
200
|
-
*
|
|
201
171
|
* @param count How many places to shift the array.
|
|
202
172
|
* @param fillValue The value to fill empty spaces with.
|
|
203
173
|
* @returns The new value of this.
|