Skip to content

Commit

Permalink
feat: Support conversion from/to BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Feb 10, 2025
1 parent d0f7475 commit 1760d02
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 92 deletions.
51 changes: 30 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ API

### Utility

* Long.**isLong**(obj: `*`): `boolean`<br />
* type **LongLike**: `Long | number | bigint | string`<br />
Any value or object that either is or can be converted to a Long.

* Long.**isLong**(obj: `any`): `boolean`<br />
Tests if the specified object is a Long.

* Long.**fromBits**(lowBits: `number`, highBits: `number`, unsigned?: `boolean`): `Long`<br />
Expand All @@ -124,28 +127,31 @@ API
* Long.**fromNumber**(value: `number`, unsigned?: `boolean`): `Long`<br />
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`<br />
Returns a Long representing the given big integer.

* Long.**fromString**(str: `string`, unsigned?: `boolean`, radix?: `number`)<br />
Long.**fromString**(str: `string`, radix: `number`)<br />
Returns a Long representation of the given string, written using the specified radix.

* Long.**fromValue**(val: `*`, unsigned?: `boolean`): `Long`<br />
* Long.**fromValue**(val: `LongLike`, unsigned?: `boolean`): `Long`<br />
Converts the specified value to a Long using the appropriate from* function for its type.

### Methods

* Long#**add**(addend: `Long | number | string`): `Long`<br />
* Long#**add**(addend: `LongLike`): `Long`<br />
Returns the sum of this and the specified Long.

* Long#**and**(other: `Long | number | string`): `Long`<br />
* Long#**and**(other: `LongLike`): `Long`<br />
Returns the bitwise AND of this Long and the specified.

* Long#**compare**/**comp**(other: `Long | number | string`): `number`<br />
* Long#**compare**/**comp**(other: `LongLike`): `number`<br />
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`<br />
* Long#**divide**/**div**(divisor: `LongLike`): `Long`<br />
Returns this Long divided by the specified.

* Long#**equals**/**eq**(other: `Long | number | string`): `boolean`<br />
* Long#**equals**/**eq**(other: `LongLike`): `boolean`<br />
Tests if this Long's value equals the specified's.

* Long#**getHighBits**(): `number`<br />
Expand All @@ -163,10 +169,10 @@ API
* Long#**getNumBitsAbs**(): `number`<br />
Gets the number of bits needed to represent the absolute value of this Long.

* Long#**greaterThan**/**gt**(other: `Long | number | string`): `boolean`<br />
* Long#**greaterThan**/**gt**(other: `LongLike`): `boolean`<br />
Tests if this Long's value is greater than the specified's.

* Long#**greaterThanOrEqual**/**gte**/**ge**(other: `Long | number | string`): `boolean`<br />
* Long#**greaterThanOrEqual**/**gte**/**ge**(other: `LongLike`): `boolean`<br />
Tests if this Long's value is greater than or equal the specified's.

* Long#**isEven**(): `boolean`<br />
Expand All @@ -184,16 +190,16 @@ API
* Long#**isZero**/**eqz**(): `boolean`<br />
Tests if this Long's value equals zero.

* Long#**lessThan**/**lt**(other: `Long | number | string`): `boolean`<br />
* Long#**lessThan**/**lt**(other: `LongLike`): `boolean`<br />
Tests if this Long's value is less than the specified's.

* Long#**lessThanOrEqual**/**lte**/**le**(other: `Long | number | string`): `boolean`<br />
* Long#**lessThanOrEqual**/**lte**/**le**(other: `LongLike`): `boolean`<br />
Tests if this Long's value is less than or equal the specified's.

* Long#**modulo**/**mod**/**rem**(divisor: `Long | number | string`): `Long`<br />
* Long#**modulo**/**mod**/**rem**(divisor: `LongLike`): `Long`<br />
Returns this Long modulo the specified.

* Long#**multiply**/**mul**(multiplier: `Long | number | string`): `Long`<br />
* Long#**multiply**/**mul**(multiplier: `LongLike`): `Long`<br />
Returns the product of this and the specified Long.

* Long#**negate**/**neg**(): `Long`<br />
Expand All @@ -208,28 +214,28 @@ API
* Long#**countTrailingZeros**/**ctz**(): `number`<br />
Returns count trailing zeros of this Long.

* Long#**notEquals**/**neq**/**ne**(other: `Long | number | string`): `boolean`<br />
* Long#**notEquals**/**neq**/**ne**(other: `LongLike`): `boolean`<br />
Tests if this Long's value differs from the specified's.

* Long#**or**(other: `Long | number | string`): `Long`<br />
* Long#**or**(other: `LongLike`): `Long`<br />
Returns the bitwise OR of this Long and the specified.

* Long#**shiftLeft**/**shl**(numBits: `Long | number | string`): `Long`<br />
* Long#**shiftLeft**/**shl**(numBits: `Long | number`): `Long`<br />
Returns this Long with bits shifted to the left by the given amount.

* Long#**shiftRight**/**shr**(numBits: `Long | number | string`): `Long`<br />
* Long#**shiftRight**/**shr**(numBits: `Long | number`): `Long`<br />
Returns this Long with bits arithmetically shifted to the right by the given amount.

* Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number | string`): `Long`<br />
* Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number`): `Long`<br />
Returns this Long with bits logically shifted to the right by the given amount.

* Long#**rotateLeft**/**rotl**(numBits: `Long | number | string`): `Long`<br />
* Long#**rotateLeft**/**rotl**(numBits: `Long | number`): `Long`<br />
Returns this Long with bits rotated to the left by the given amount.

* Long#**rotateRight**/**rotr**(numBits: `Long | number | string`): `Long`<br />
* Long#**rotateRight**/**rotr**(numBits: `Long | number`): `Long`<br />
Returns this Long with bits rotated to the right by the given amount.

* Long#**subtract**/**sub**(subtrahend: `Long | number | string`): `Long`<br />
* Long#**subtract**/**sub**(subtrahend: `LongLike`): `Long`<br />
Returns the difference of this and the specified Long.

* Long#**toBytes**(le?: `boolean`): `number[]`<br />
Expand All @@ -247,6 +253,9 @@ API
* Long#**toNumber**(): `number`<br />
Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).

* Long#**toBigInt**(): `bigint`<br />
Converts the Long to its big integer representation.

* Long#**toSigned**(): `Long`<br />
Converts this Long to signed.

Expand Down
Loading

0 comments on commit 1760d02

Please sign in to comment.