Integer
Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers.
See exported functions for more convenient ways of operating integers.
Use int()
function to create new integers, isInt()
to check if given object is integer,
inSafeRange()
to check if it is safe to convert given value to native number,
toNumber()
and toString()
to convert given integer to number or string respectively.
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
high: number The high 32 bits as a signed value. |
|
public |
low: number The low 32 bits as a signed value. |
Method Summary
Public Methods | ||
public |
Returns the sum of this and the specified Integer. |
|
public |
Returns the bitwise AND of this Integer and the specified. |
|
public |
Compares this Integer's value with the specified's. |
|
public |
Returns this Integer divided by the specified. |
|
public |
Tests if this Integer's value equals the specified's. |
|
public |
getHighBits(): number Gets the high 32 bits as a signed integer. |
|
public |
getLowBits(): number Gets the low 32 bits as a signed integer. |
|
public |
getNumBitsAbs(): number Gets the number of bits needed to represent the absolute value of this Integer. |
|
public |
greaterThan(other: Integer | number | string): boolean Tests if this Integer's value is greater than the specified's. |
|
public |
greaterThanOrEqual(other: Integer | number | string): boolean Tests if this Integer's value is greater than or equal the specified's. |
|
public |
inSafeRange(): * |
|
public |
isEven(): boolean Tests if this Integer's value is even. |
|
public |
isNegative(): boolean Tests if this Integer's value is negative. |
|
public |
isOdd(): boolean Tests if this Integer's value is odd. |
|
public |
isPositive(): boolean Tests if this Integer's value is positive. |
|
public |
isZero(): boolean Tests if this Integer's value equals zero. |
|
public |
Tests if this Integer's value is less than the specified's. |
|
public |
lessThanOrEqual(other: Integer | number | string): boolean Tests if this Integer's value is less than or equal the specified's. |
|
public |
Returns this Integer modulo the specified. |
|
public |
Returns the product of this and the specified Integer. |
|
public |
Negates this Integer's value. |
|
public |
Returns the bitwise NOT of this Integer. |
|
public |
Tests if this Integer's value differs from the specified's. |
|
public |
Returns the bitwise OR of this Integer and the specified. |
|
public |
Returns this Integer with bits shifted to the left by the given amount. |
|
public |
shiftRight(numBits: number | !Integer): Integer Returns this Integer with bits arithmetically shifted to the right by the given amount. |
|
public |
Returns the difference of this and the specified Integer. |
|
public |
toBigInt(): bigint Converts the Integer to a BigInt representation of this value |
|
public |
toInt(): number Converts the Integer to an exact javascript Number, assuming it is a 32 bit integer. |
|
public |
toNumber(): number Converts the Integer to a the nearest floating-point representation of this value (double, 53 bit mantissa). |
|
public |
toString(radix: number=): string Converts the Integer to a string written in the specified radix. |
|
public |
valueOf(): bigint Converts the Integer to it primitive value. |
since 5.4.0 |
public |
Returns the bitwise XOR of this Integer and the given one. |
Public Constructors
public constructor() source
Public Members
Public Methods
public add(addend: Integer | number | string): Integer source
Returns the sum of this and the specified Integer.
Params:
Name | Type | Attribute | Description |
addend | Integer | number | string |
|
Addend |
public and(other: Integer | number | string): Integer source
Returns the bitwise AND of this Integer and the specified.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other Integer |
public compare(other: Integer | number | string): number source
Compares this Integer's value with the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
number | 0 if they are the same, 1 if the this is greater and -1 if the given one is greater |
public div(divisor: Integer | number | string): Integer source
Returns this Integer divided by the specified.
Params:
Name | Type | Attribute | Description |
divisor | Integer | number | string |
|
Divisor |
public equals(other: Integer | number | string): boolean source
Tests if this Integer's value equals the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
boolean |
public getHighBits(): number source
Gets the high 32 bits as a signed integer.
Return:
number | Signed high bits |
public getLowBits(): number source
Gets the low 32 bits as a signed integer.
Return:
number | Signed low bits |
public getNumBitsAbs(): number source
Gets the number of bits needed to represent the absolute value of this Integer.
Return:
number |
public greaterThan(other: Integer | number | string): boolean source
Tests if this Integer's value is greater than the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
boolean |
public greaterThanOrEqual(other: Integer | number | string): boolean source
Tests if this Integer's value is greater than or equal the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
boolean |
public lessThan(other: Integer | number | string): boolean source
Tests if this Integer's value is less than the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
boolean |
public lessThanOrEqual(other: Integer | number | string): boolean source
Tests if this Integer's value is less than or equal the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
boolean |
public modulo(divisor: Integer | number | string): Integer source
Returns this Integer modulo the specified.
Params:
Name | Type | Attribute | Description |
divisor | Integer | number | string |
|
Divisor |
public multiply(multiplier: Integer | number | string): Integer source
Returns the product of this and the specified Integer.
Params:
Name | Type | Attribute | Description |
multiplier | Integer | number | string |
|
Multiplier |
public notEquals(other: Integer | number | string): boolean source
Tests if this Integer's value differs from the specified's.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other value |
Return:
boolean |
public or(other: Integer | number | string): Integer source
Returns the bitwise OR of this Integer and the specified.
Params:
Name | Type | Attribute | Description |
other | Integer | number | string |
|
Other Integer |
public shiftLeft(numBits: number | !Integer): Integer source
Returns this Integer with bits shifted to the left by the given amount.
Params:
Name | Type | Attribute | Description |
numBits | number | !Integer | Number of bits |
public shiftRight(numBits: number | !Integer): Integer source
Returns this Integer with bits arithmetically shifted to the right by the given amount.
Params:
Name | Type | Attribute | Description |
numBits | number | !Integer | Number of bits |
public subtract(subtrahend: Integer | number | string): Integer source
Returns the difference of this and the specified Integer.
Params:
Name | Type | Attribute | Description |
subtrahend | Integer | number | string |
|
Subtrahend |
public toBigInt(): bigint source
Converts the Integer to a BigInt representation of this value
Return:
bigint |
public toInt(): number source
Converts the Integer to an exact javascript Number, assuming it is a 32 bit integer.
Return:
number |
public toNumber(): number source
Converts the Integer to a the nearest floating-point representation of this value (double, 53 bit mantissa).
Return:
number |
public toString(radix: number=): string source
Converts the Integer to a string written in the specified radix.
Params:
Name | Type | Attribute | Description |
radix | number= | Radix (2-36), defaults to 10 |
Return:
string |
Throw:
RangeError |
If |
public valueOf(): bigint since 5.4.0 source
Converts the Integer to it primitive value.
Return:
bigint |