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.
Acceptable signatures are:
Optional
low: string | number | bigintThe low (signed) 32 bits of the long
Optional
high: number | booleanThe high (signed) 32 bits of the long
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
The high 32 bits as a signed value.
The low 32 bits as a signed value.
Whether unsigned or not.
Static
MAX_Maximum unsigned value.
Static
MAX_Maximum signed value.
Static
MIN_Minimum signed value.
Static
NEG_Signed negative one.
Static
ONESigned one.
Static
TWO_Static
UONEUnsigned one.
Static
UZEROUnsigned zero.
Static
ZEROSigned zero
An indicator used to reliably determine if an object is a Long or not.
This is an alias of compare
This is an alias of equals
This is an alias of isZero
This is an alias of greaterThanOrEqual
This is an alias of greaterThan
This is an alias of greaterThanOrEqual
Prints a human-readable string of BSON value information If invoked manually without node.js.inspect function, this will default to a modified JSON.stringify
Optional
depth: numberOptional
options: unknownOptional
inspect: InspectFnThis is an alias of lessThanOrEqual
This is an alias of lessThan.
This is an alias of lessThanOrEqual
This is an alias of notEquals
This is an alias of notEquals
This is an alias of shiftRight
This is an alias of shiftRightUnsigned
This is an alias of shiftRightUnsigned
Optional
options: EJSONOptionsStatic
fromReturns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
The number in question
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
The corresponding Long value
Static
fromReturns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.
The low 32 bits
The high 32 bits
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
The corresponding Long value
Static
fromCreates a Long from its byte representation.
Byte representation
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
Optional
le: booleanWhether little or big endian, defaults to big endian
The corresponding Long value
Static
fromStatic
fromStatic
fromOptional
options: EJSONOptionsStatic
fromStatic
fromReturns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
The number in question
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
The corresponding Long value
Static
fromReturns a signed Long representation of the given string, written using radix 10.
If the input string is empty, this function will throw a BSONError.
If input string does not have valid signed 64-bit Long representation, this method will return a coerced value:
The textual representation of the Long
The corresponding Long value
Returns a signed Long representation of the given string, written using the provided radix.
If the input string is empty or a provided radix is not within (2-36), this function will throw a BSONError.
If input parameters do not have valid signed 64-bit Long representation, this method will return a coerced value:
The textual representation of the Long
Optional
radix: numberThe radix in which the text is written (2-36), defaults to 10
The corresponding Long value
Returns a Long representation of the given string, written using radix 10.
If the input string is empty, this function will throw a BSONError.
If input parameters do not have a valid 64-bit Long representation, this method will return a coerced value:
The textual representation of the Long
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
The corresponding Long value
Returns a Long representation of the given string, written using the specified radix.
If the input string is empty or a provided radix is not within (2-36), this function will throw a BSONError.
If input parameters do not have a valid 64-bit Long representation, this method will return a coerced value:
The textual representation of the Long
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
Optional
radix: numberThe radix in which the text is written (2-36), defaults to 10
The corresponding Long value
Static
fromReturns a signed Long representation of the given string, written using radix 10. Will throw an error if the given text is not exactly representable as a Long. Throws an error if any of the following conditions are true:
The textual representation of the Long
The corresponding Long value
Returns a Long representation of the given string, written using the radix 10. Will throw an error if the given parameters are not exactly representable as a Long. Throws an error if any of the following conditions are true:
The textual representation of the Long
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
The corresponding Long value
Returns a signed Long representation of the given string, written using the specified radix. Will throw an error if the given parameters are not exactly representable as a Long. Throws an error if any of the following conditions are true:
The textual representation of the Long
Optional
radix: booleanThe radix in which the text is written (2-36), defaults to 10
The corresponding Long value
Returns a Long representation of the given string, written using the specified radix. Will throw an error if the given parameters are not exactly representable as a Long. Throws an error if any of the following conditions are true:
The textual representation of the Long
Optional
unsigned: booleanWhether unsigned or not, defaults to signed
Optional
radix: numberThe radix in which the text is written (2-36), defaults to 10
The corresponding Long value
Static
fromStatic
isGenerated using TypeDoc
A class representing a 64-bit integer
Remarks
The internal representation of a long is the two given signed, 32-bit values. We use 32-bit pieces because these are the size of integers on which Javascript performs bit-operations. For operations like addition and multiplication, we split each number into 16 bit pieces, which can easily be multiplied within Javascript's floating-point representation without overflow or change in sign. In the algorithms below, we frequently reduce the negative case to the positive case by negating the input(s) and then post-processing the result. Note that we must ALWAYS check specially whether those values are MIN_VALUE (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as a positive number, it overflows back into a negative). Not handling this case would often result in infinite recursion. Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.