Class: Long

Long

Long class for only unsigned integers 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. 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.

new Long(low, high)

Parameters:
Name Type Description
low number The low (signed) 32 bits of the long.
high number The high (signed) 32 bits of the long.

Methods


<static> fromInt(value)

Returns a Long representing the given (32-bit) integer value.
Parameters:
Name Type Description
value number The 32-bit integer in question.
Returns:
The corresponding Long value.
Type
Long

<static> fromNumber(value)

Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
Parameters:
Name Type Description
value number The number in question.
Returns:
The corresponding Long value.
Type
Long

<static> fromBits(lowBits, highBits)

Returns a Long representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits.
Parameters:
Name Type Description
lowBits number The low 32-bits.
highBits number The high 32-bits.
Returns:
The corresponding Long value.
Type
Long

compare()

Compares this Long with the given one.
Returns:
0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.
Type
number

negate()

Return the negation
Returns:
The negation of this value.
Type
Long

add(other)

Returns the sum of this and the given Long.
Parameters:
Name Type Description
other Long Long to add to this one.
Returns:
The sum of this and the given Long.
Type
Long

subtract(other)

Returns the difference of this and the given Long.
Parameters:
Name Type Description
other Long Long to subtract from this.
Returns:
The difference of this and the given Long.
Type
Long

multiply(other)

Returns the product of this and the given long.
Parameters:
Name Type Description
other Long Long to multiply with this.
Returns:
The product of this and the other.
Type
Long

and(other)

Returns the bitwise-AND of this Long and the given one.
Parameters:
Name Type Description
other Long The Long with which to AND.
Returns:
The bitwise-AND of this and the other.
Type
Long

or(other)

Returns the bitwise-OR of this Long and the given one.
Parameters:
Name Type Description
other Long The Long with which to OR.
Returns:
The bitwise-OR of this and the other.
Type
Long

shiftRightUnsigned(numBits)

Returns this Long with bits shifted to the right by the given amount, with the new top bits matching the current sign bit.
Parameters:
Name Type Description
numBits number The number of bits by which to shift.
Returns:
This shifted to the right by the given amount, with zeros placed into the new leading bits.
Type
Long