From 1760d02e138f790805ece2634fb9a284e2ec4053 Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 10 Feb 2025 14:19:15 +0100 Subject: [PATCH] feat: Support conversion from/to BigInt --- README.md | 51 +++++++++++++++----------- index.js | 98 ++++++++++++++++++++++++++++++++++---------------- tests/index.js | 24 +++++++++++++ umd/index.d.ts | 84 ++++++++++++++++++++++--------------------- 4 files changed, 165 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index 9da2e79..1b64a94 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,10 @@ API ### Utility -* Long.**isLong**(obj: `*`): `boolean`
+* type **LongLike**: `Long | number | bigint | string`
+ Any value or object that either is or can be converted to a Long. + +* Long.**isLong**(obj: `any`): `boolean`
Tests if the specified object is a Long. * Long.**fromBits**(lowBits: `number`, highBits: `number`, unsigned?: `boolean`): `Long`
@@ -124,28 +127,31 @@ API * Long.**fromNumber**(value: `number`, unsigned?: `boolean`): `Long`
Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. +* Long.**fromBigInt**(value: `bigint`, unsigned?: `boolean`): `Long`
+ Returns a Long representing the given big integer. + * Long.**fromString**(str: `string`, unsigned?: `boolean`, radix?: `number`)
Long.**fromString**(str: `string`, radix: `number`)
Returns a Long representation of the given string, written using the specified radix. -* Long.**fromValue**(val: `*`, unsigned?: `boolean`): `Long`
+* Long.**fromValue**(val: `LongLike`, unsigned?: `boolean`): `Long`
Converts the specified value to a Long using the appropriate from* function for its type. ### Methods -* Long#**add**(addend: `Long | number | string`): `Long`
+* Long#**add**(addend: `LongLike`): `Long`
Returns the sum of this and the specified Long. -* Long#**and**(other: `Long | number | string`): `Long`
+* Long#**and**(other: `LongLike`): `Long`
Returns the bitwise AND of this Long and the specified. -* Long#**compare**/**comp**(other: `Long | number | string`): `number`
+* Long#**compare**/**comp**(other: `LongLike`): `number`
Compares this Long's value with the specified's. Returns `0` if they are the same, `1` if the this is greater and `-1` if the given one is greater. -* Long#**divide**/**div**(divisor: `Long | number | string`): `Long`
+* Long#**divide**/**div**(divisor: `LongLike`): `Long`
Returns this Long divided by the specified. -* Long#**equals**/**eq**(other: `Long | number | string`): `boolean`
+* Long#**equals**/**eq**(other: `LongLike`): `boolean`
Tests if this Long's value equals the specified's. * Long#**getHighBits**(): `number`
@@ -163,10 +169,10 @@ API * Long#**getNumBitsAbs**(): `number`
Gets the number of bits needed to represent the absolute value of this Long. -* Long#**greaterThan**/**gt**(other: `Long | number | string`): `boolean`
+* Long#**greaterThan**/**gt**(other: `LongLike`): `boolean`
Tests if this Long's value is greater than the specified's. -* Long#**greaterThanOrEqual**/**gte**/**ge**(other: `Long | number | string`): `boolean`
+* Long#**greaterThanOrEqual**/**gte**/**ge**(other: `LongLike`): `boolean`
Tests if this Long's value is greater than or equal the specified's. * Long#**isEven**(): `boolean`
@@ -184,16 +190,16 @@ API * Long#**isZero**/**eqz**(): `boolean`
Tests if this Long's value equals zero. -* Long#**lessThan**/**lt**(other: `Long | number | string`): `boolean`
+* Long#**lessThan**/**lt**(other: `LongLike`): `boolean`
Tests if this Long's value is less than the specified's. -* Long#**lessThanOrEqual**/**lte**/**le**(other: `Long | number | string`): `boolean`
+* Long#**lessThanOrEqual**/**lte**/**le**(other: `LongLike`): `boolean`
Tests if this Long's value is less than or equal the specified's. -* Long#**modulo**/**mod**/**rem**(divisor: `Long | number | string`): `Long`
+* Long#**modulo**/**mod**/**rem**(divisor: `LongLike`): `Long`
Returns this Long modulo the specified. -* Long#**multiply**/**mul**(multiplier: `Long | number | string`): `Long`
+* Long#**multiply**/**mul**(multiplier: `LongLike`): `Long`
Returns the product of this and the specified Long. * Long#**negate**/**neg**(): `Long`
@@ -208,28 +214,28 @@ API * Long#**countTrailingZeros**/**ctz**(): `number`
Returns count trailing zeros of this Long. -* Long#**notEquals**/**neq**/**ne**(other: `Long | number | string`): `boolean`
+* Long#**notEquals**/**neq**/**ne**(other: `LongLike`): `boolean`
Tests if this Long's value differs from the specified's. -* Long#**or**(other: `Long | number | string`): `Long`
+* Long#**or**(other: `LongLike`): `Long`
Returns the bitwise OR of this Long and the specified. -* Long#**shiftLeft**/**shl**(numBits: `Long | number | string`): `Long`
+* Long#**shiftLeft**/**shl**(numBits: `Long | number`): `Long`
Returns this Long with bits shifted to the left by the given amount. -* Long#**shiftRight**/**shr**(numBits: `Long | number | string`): `Long`
+* Long#**shiftRight**/**shr**(numBits: `Long | number`): `Long`
Returns this Long with bits arithmetically shifted to the right by the given amount. -* Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number | string`): `Long`
+* Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number`): `Long`
Returns this Long with bits logically shifted to the right by the given amount. -* Long#**rotateLeft**/**rotl**(numBits: `Long | number | string`): `Long`
+* Long#**rotateLeft**/**rotl**(numBits: `Long | number`): `Long`
Returns this Long with bits rotated to the left by the given amount. -* Long#**rotateRight**/**rotr**(numBits: `Long | number | string`): `Long`
+* Long#**rotateRight**/**rotr**(numBits: `Long | number`): `Long`
Returns this Long with bits rotated to the right by the given amount. -* Long#**subtract**/**sub**(subtrahend: `Long | number | string`): `Long`
+* Long#**subtract**/**sub**(subtrahend: `LongLike`): `Long`
Returns the difference of this and the specified Long. * Long#**toBytes**(le?: `boolean`): `number[]`
@@ -247,6 +253,9 @@ API * Long#**toNumber**(): `number`
Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). +* Long#**toBigInt**(): `bigint`
+ Converts the Long to its big integer representation. + * Long#**toSigned**(): `Long`
Converts this Long to signed. diff --git a/index.js b/index.js index f04775e..6f4343c 100644 --- a/index.js +++ b/index.js @@ -315,7 +315,7 @@ function fromValue(val, unsigned) { /** * Converts the specified value to a Long using the appropriate from* function for its type. * @function - * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value + * @param {!Long|number|bigint|string|!{low: number, high: number, unsigned: boolean}} val Value * @param {boolean=} unsigned Whether unsigned or not, defaults to signed * @returns {!Long} */ @@ -639,7 +639,7 @@ LongPrototype.isEven = function isEven() { /** * Tests if this Long's value equals the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.equals = function equals(other) { @@ -653,7 +653,7 @@ LongPrototype.equals = function equals(other) { /** * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.eq = LongPrototype.equals; @@ -661,7 +661,7 @@ LongPrototype.eq = LongPrototype.equals; /** * Tests if this Long's value differs from the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.notEquals = function notEquals(other) { @@ -671,7 +671,7 @@ LongPrototype.notEquals = function notEquals(other) { /** * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.neq = LongPrototype.notEquals; @@ -679,7 +679,7 @@ LongPrototype.neq = LongPrototype.notEquals; /** * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.ne = LongPrototype.notEquals; @@ -687,7 +687,7 @@ LongPrototype.ne = LongPrototype.notEquals; /** * Tests if this Long's value is less than the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.lessThan = function lessThan(other) { @@ -697,7 +697,7 @@ LongPrototype.lessThan = function lessThan(other) { /** * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.lt = LongPrototype.lessThan; @@ -705,7 +705,7 @@ LongPrototype.lt = LongPrototype.lessThan; /** * Tests if this Long's value is less than or equal the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { @@ -715,7 +715,7 @@ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { /** * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.lte = LongPrototype.lessThanOrEqual; @@ -723,7 +723,7 @@ LongPrototype.lte = LongPrototype.lessThanOrEqual; /** * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.le = LongPrototype.lessThanOrEqual; @@ -731,7 +731,7 @@ LongPrototype.le = LongPrototype.lessThanOrEqual; /** * Tests if this Long's value is greater than the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.greaterThan = function greaterThan(other) { @@ -741,7 +741,7 @@ LongPrototype.greaterThan = function greaterThan(other) { /** * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.gt = LongPrototype.greaterThan; @@ -749,7 +749,7 @@ LongPrototype.gt = LongPrototype.greaterThan; /** * Tests if this Long's value is greater than or equal the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { @@ -759,7 +759,7 @@ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { /** * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.gte = LongPrototype.greaterThanOrEqual; @@ -767,7 +767,7 @@ LongPrototype.gte = LongPrototype.greaterThanOrEqual; /** * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {boolean} */ LongPrototype.ge = LongPrototype.greaterThanOrEqual; @@ -775,7 +775,7 @@ LongPrototype.ge = LongPrototype.greaterThanOrEqual; /** * Compares this Long's value with the specified's. * @this {!Long} - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {number} 0 if they are the same, 1 if the this is greater and -1 * if the given one is greater */ @@ -800,7 +800,7 @@ LongPrototype.compare = function compare(other) { /** * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. * @function - * @param {!Long|number|string} other Other value + * @param {!Long|number|bigint|string} other Other value * @returns {number} 0 if they are the same, 1 if the this is greater and -1 * if the given one is greater */ @@ -827,7 +827,7 @@ LongPrototype.neg = LongPrototype.negate; /** * Returns the sum of this and the specified Long. * @this {!Long} - * @param {!Long|number|string} addend Addend + * @param {!Long|number|bigint|string} addend Addend * @returns {!Long} Sum */ LongPrototype.add = function add(addend) { @@ -864,7 +864,7 @@ LongPrototype.add = function add(addend) { /** * Returns the difference of this and the specified Long. * @this {!Long} - * @param {!Long|number|string} subtrahend Subtrahend + * @param {!Long|number|bigint|string} subtrahend Subtrahend * @returns {!Long} Difference */ LongPrototype.subtract = function subtract(subtrahend) { @@ -876,7 +876,7 @@ LongPrototype.subtract = function subtract(subtrahend) { /** * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. * @function - * @param {!Long|number|string} subtrahend Subtrahend + * @param {!Long|number|bigint|string} subtrahend Subtrahend * @returns {!Long} Difference */ LongPrototype.sub = LongPrototype.subtract; @@ -884,7 +884,7 @@ LongPrototype.sub = LongPrototype.subtract; /** * Returns the product of this and the specified Long. * @this {!Long} - * @param {!Long|number|string} multiplier Multiplier + * @param {!Long|number|bigint|string} multiplier Multiplier * @returns {!Long} Product */ LongPrototype.multiply = function multiply(multiplier) { @@ -961,7 +961,7 @@ LongPrototype.multiply = function multiply(multiplier) { /** * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. * @function - * @param {!Long|number|string} multiplier Multiplier + * @param {!Long|number|bigint|string} multiplier Multiplier * @returns {!Long} Product */ LongPrototype.mul = LongPrototype.multiply; @@ -970,7 +970,7 @@ LongPrototype.mul = LongPrototype.multiply; * Returns this Long divided by the specified. The result is signed if this Long is signed or * unsigned if this Long is unsigned. * @this {!Long} - * @param {!Long|number|string} divisor Divisor + * @param {!Long|number|bigint|string} divisor Divisor * @returns {!Long} Quotient */ LongPrototype.divide = function divide(divisor) { @@ -1083,7 +1083,7 @@ LongPrototype.divide = function divide(divisor) { /** * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. * @function - * @param {!Long|number|string} divisor Divisor + * @param {!Long|number|bigint|string} divisor Divisor * @returns {!Long} Quotient */ LongPrototype.div = LongPrototype.divide; @@ -1091,7 +1091,7 @@ LongPrototype.div = LongPrototype.divide; /** * Returns this Long modulo the specified. * @this {!Long} - * @param {!Long|number|string} divisor Divisor + * @param {!Long|number|bigint|string} divisor Divisor * @returns {!Long} Remainder */ LongPrototype.modulo = function modulo(divisor) { @@ -1115,7 +1115,7 @@ LongPrototype.modulo = function modulo(divisor) { /** * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. * @function - * @param {!Long|number|string} divisor Divisor + * @param {!Long|number|bigint|string} divisor Divisor * @returns {!Long} Remainder */ LongPrototype.mod = LongPrototype.modulo; @@ -1123,7 +1123,7 @@ LongPrototype.mod = LongPrototype.modulo; /** * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. * @function - * @param {!Long|number|string} divisor Divisor + * @param {!Long|number|bigint|string} divisor Divisor * @returns {!Long} Remainder */ LongPrototype.rem = LongPrototype.modulo; @@ -1174,7 +1174,7 @@ LongPrototype.ctz = LongPrototype.countTrailingZeros; /** * Returns the bitwise AND of this Long and the specified. * @this {!Long} - * @param {!Long|number|string} other Other Long + * @param {!Long|number|bigint|string} other Other Long * @returns {!Long} */ LongPrototype.and = function and(other) { @@ -1186,7 +1186,7 @@ LongPrototype.and = function and(other) { /** * Returns the bitwise OR of this Long and the specified. * @this {!Long} - * @param {!Long|number|string} other Other Long + * @param {!Long|number|bigint|string} other Other Long * @returns {!Long} */ LongPrototype.or = function or(other) { @@ -1198,7 +1198,7 @@ LongPrototype.or = function or(other) { /** * Returns the bitwise XOR of this Long and the given one. * @this {!Long} - * @param {!Long|number|string} other Other Long + * @param {!Long|number|bigint|string} other Other Long * @returns {!Long} */ LongPrototype.xor = function xor(other) { @@ -1464,4 +1464,40 @@ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) { ); }; +// Support conversion to/from BigInt where available +if (typeof BigInt === "function") { + + /** + * Returns a Long representing the given big integer. + * @function + * @param {number} value The big integer value + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ + Long.fromBigInt = function fromBigInt(value, unsigned) { + var lowBits = Number(BigInt.asIntN(32, value)); + var highBits = Number(BigInt.asIntN(32, value >> BigInt(32))); + return fromBits(lowBits, highBits, unsigned); + }; + + // Override + Long.fromValue = function fromValueWithBigInt(value, unsigned) { + if (typeof value === "bigint") + return fromBigInt(value, unsigned); + return fromValue(value, unsigned); + } + + /** + * Converts the Long to its big integer representation. + * @this {!Long} + * @returns {bigint} + */ + LongPrototype.toBigInt = function toBigInt() { + var lowBigInt = BigInt(this.low >>> 0); + var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high); + return highBigInt << BigInt(32) | lowBigInt; + }; + +} + export default Long; diff --git a/tests/index.js b/tests/index.js index b935f9a..6711fef 100644 --- a/tests/index.js +++ b/tests/index.js @@ -209,6 +209,29 @@ var tests = [ // BEGIN TEST CASES assert.deepEqual(longVal1.ctz(), 0); assert.deepEqual(longVal2.ctz(), 32); assert.deepEqual(longVal3.ctz(), 0); + }, + + function testBigInt() { + if (typeof BigInt !== "function") return + + var values = [ + { signed: 0n, unsigned: 0n }, + { signed: 1n, unsigned: 1n }, + { signed: -1n, unsigned: 18446744073709551615n }, + { signed: 9223372036854775807n, unsigned: 9223372036854775807n }, + { signed: -9223372036854775808n, unsigned: 9223372036854775808n } + ]; + + for (var i = 0; i < values.length; i++) { + var signedFromSigned = Long.fromBigInt(values[i].signed); + assert.strictEqual(signedFromSigned.toBigInt(), values[i].signed); + var unsignedFromSigned = Long.fromBigInt(values[i].signed, true); + assert.strictEqual(unsignedFromSigned.toBigInt(), values[i].unsigned); + var unsignedFromUnsigned = Long.fromBigInt(values[i].unsigned, true); + assert.strictEqual(unsignedFromUnsigned.toBigInt(), values[i].unsigned); + var signedFromUnsigned = Long.fromBigInt(values[i].unsigned); + assert.strictEqual(signedFromUnsigned.toBigInt(), values[i].signed); + } } ]; // END TEST CASES @@ -248,6 +271,7 @@ console.log(); console.log("Check UMD fallback"); import { createRequire } from "module"; +import { sign } from "crypto"; const require = createRequire(import.meta.url); const LongUMD = require("../umd/"); assert(typeof LongUMD == "function"); diff --git a/umd/index.d.ts b/umd/index.d.ts index c6b1440..594663d 100644 --- a/umd/index.d.ts +++ b/umd/index.d.ts @@ -1,9 +1,11 @@ +type LongLike = Long | number | bigint | string | { low: number; high: number; unsigned: boolean }; + declare class Long { /** * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs. */ constructor(low: number, high?: number, unsigned?: boolean); - + /** * Maximum unsigned value. */ @@ -74,6 +76,11 @@ declare class Long { */ static fromNumber(value: number, unsigned?: boolean): Long; + /** + * Returns a Long representing the given big integer value. + */ + static fromBigInt(value: bigint, unsigned?: boolean): Long; + /** * Returns a Long representation of the given string, written using the specified radix. */ @@ -106,54 +113,47 @@ declare class Long { /** * Converts the specified value to a Long. */ - static fromValue( - val: - | Long - | number - | string - | { low: number; high: number; unsigned: boolean }, - unsigned?: boolean - ): Long; + static fromValue(val: LongLike, unsigned?: boolean): Long; /** * Returns the sum of this and the specified Long. */ - add(addend: number | Long | string): Long; + add(addend: LongLike): Long; /** * Returns the bitwise AND of this Long and the specified. */ - and(other: Long | number | string): Long; + and(other: LongLike): Long; /** * Compares this Long's value with the specified's. */ - compare(other: Long | number | string): number; + compare(other: LongLike): number; /** * Compares this Long's value with the specified's. */ - comp(other: Long | number | string): number; + comp(other: LongLike): number; /** * Returns this Long divided by the specified. */ - divide(divisor: Long | number | string): Long; + divide(divisor: LongLike): Long; /** * Returns this Long divided by the specified. */ - div(divisor: Long | number | string): Long; + div(divisor: LongLike): Long; /** * Tests if this Long's value equals the specified's. */ - equals(other: Long | number | string): boolean; + equals(other: LongLike): boolean; /** * Tests if this Long's value equals the specified's. */ - eq(other: Long | number | string): boolean; + eq(other: LongLike): boolean; /** * Gets the high 32 bits as a signed integer. @@ -183,27 +183,27 @@ declare class Long { /** * Tests if this Long's value is greater than the specified's. */ - greaterThan(other: Long | number | string): boolean; + greaterThan(other: LongLike): boolean; /** * Tests if this Long's value is greater than the specified's. */ - gt(other: Long | number | string): boolean; + gt(other: LongLike): boolean; /** * Tests if this Long's value is greater than or equal the specified's. */ - greaterThanOrEqual(other: Long | number | string): boolean; + greaterThanOrEqual(other: LongLike): boolean; /** * Tests if this Long's value is greater than or equal the specified's. */ - gte(other: Long | number | string): boolean; + gte(other: LongLike): boolean; /** * Tests if this Long's value is greater than or equal the specified's. */ - ge(other: Long | number | string): boolean; + ge(other: LongLike): boolean; /** * Tests if this Long's value is even. @@ -238,52 +238,52 @@ declare class Long { /** * Tests if this Long's value is less than the specified's. */ - lessThan(other: Long | number | string): boolean; + lessThan(other: LongLike): boolean; /** * Tests if this Long's value is less than the specified's. */ - lt(other: Long | number | string): boolean; + lt(other: LongLike): boolean; /** * Tests if this Long's value is less than or equal the specified's. */ - lessThanOrEqual(other: Long | number | string): boolean; + lessThanOrEqual(other: LongLike): boolean; /** * Tests if this Long's value is less than or equal the specified's. */ - lte(other: Long | number | string): boolean; + lte(other: LongLike): boolean; /** * Tests if this Long's value is less than or equal the specified's. */ - le(other: Long | number | string): boolean; + le(other: LongLike): boolean; /** * Returns this Long modulo the specified. */ - modulo(other: Long | number | string): Long; + modulo(other: LongLike): Long; /** * Returns this Long modulo the specified. */ - mod(other: Long | number | string): Long; + mod(other: LongLike): Long; /** * Returns this Long modulo the specified. */ - rem(other: Long | number | string): Long; + rem(other: LongLike): Long; /** * Returns the product of this and the specified Long. */ - multiply(multiplier: Long | number | string): Long; + multiply(multiplier: LongLike): Long; /** * Returns the product of this and the specified Long. */ - mul(multiplier: Long | number | string): Long; + mul(multiplier: LongLike): Long; /** * Negates this Long's value. @@ -323,22 +323,22 @@ declare class Long { /** * Tests if this Long's value differs from the specified's. */ - notEquals(other: Long | number | string): boolean; + notEquals(other: LongLike): boolean; /** * Tests if this Long's value differs from the specified's. */ - neq(other: Long | number | string): boolean; + neq(other: LongLike): boolean; /** * Tests if this Long's value differs from the specified's. */ - ne(other: Long | number | string): boolean; + ne(other: LongLike): boolean; /** * Returns the bitwise OR of this Long and the specified. */ - or(other: Long | number | string): Long; + or(other: LongLike): Long; /** * Returns this Long with bits shifted to the left by the given amount. @@ -398,12 +398,17 @@ declare class Long { /** * Returns the difference of this and the specified Long. */ - subtract(subtrahend: number | Long | string): Long; + subtract(subtrahend: LongLike): Long; /** * Returns the difference of this and the specified Long. */ - sub(subtrahend: number | Long | string): Long; + sub(subtrahend: LongLike): Long; + + /** + * Converts the Long to a big integer. + */ + toBigInt(): bigint; /** * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. @@ -451,7 +456,6 @@ declare class Long { /** * Returns the bitwise XOR of this Long and the given one. */ - xor(other: Long | number | string): Long; + xor(other: LongLike): Long; } - export = Long;