The goog.math.Long Class

goog.math.Long(low, high)

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.

low {number}
The low (signed) 32 bits of the long.
high {number}
The high (signed) 32 bits of the long.

.MAX_VALUE {!goog.math.Long}

.MIN_VALUE {!goog.math.Long}

.NEG_ONE {!goog.math.Long}

.ONE {!goog.math.Long}

.ZERO {!goog.math.Long}

.add(other)

Returns the sum of this and the given Long.

other {goog.math.Long}
Long to add to this one.
returns {!goog.math.Long}
The sum of this and the given Long.

.and(other)

Returns the bitwise-AND of this Long and the given one.

other {goog.math.Long}
The Long with which to AND.
returns {!goog.math.Long}
The bitwise-AND of this and the other.

.compare(other)

Compares this Long with the given one.

other {goog.math.Long}
Long to compare against.
returns {number}
0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.

.div(other)

Returns this Long divided by the given one.

other {goog.math.Long}
Long by which to divide.
returns {!goog.math.Long}
This Long divided by the given one.

.equals(other)

other {goog.math.Long}
Long to compare against.
returns {boolean}
Whether this Long equals the other.

.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.

lowBits {number}
The low 32-bits.
highBits {number}
The high 32-bits.
returns {!goog.math.Long}
The corresponding Long value.

.fromInt(value)

Returns a Long representing the given (32-bit) integer value.

value {number}
The 32-bit integer in question.
returns {!goog.math.Long}
The corresponding Long value.

.fromNumber(value)

Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.

value {number}
The number in question.
returns {!goog.math.Long}
The corresponding Long value.

.fromString(str, opt_radix)

Returns a Long representation of the given string, written using the given radix.

str {string}
The textual representation of the Long.
opt_radix {number=}
The radix in which the text is written.
returns {!goog.math.Long}
The corresponding Long value.

.getHighBits()

returns {number}
The high 32-bits as a signed value.

.getLowBits()

returns {number}
The low 32-bits as a signed value.

.getLowBitsUnsigned()

returns {number}
The low 32-bits as an unsigned value.

.getNumBitsAbs()

returns {number}
Returns the number of bits needed to represent the absolute value of this Long.

.greaterThan(other)

other {goog.math.Long}
Long to compare against.
returns {boolean}
Whether this Long is greater than the other.

.greaterThanOrEqual(other)

other {goog.math.Long}
Long to compare against.
returns {boolean}
Whether this Long is greater than or equal to the other.

.isNegative()

returns {boolean}
Whether this value is negative.

.isOdd()

returns {boolean}
Whether this value is odd.

.isZero()

returns {boolean}
Whether this value is zero.

.lessThan(other)

other {goog.math.Long}
Long to compare against.
returns {boolean}
Whether this Long is less than the other.

.lessThanOrEqual(other)

other {goog.math.Long}
Long to compare against.
returns {boolean}
Whether this Long is less than or equal to the other.

.modulo(other)

Returns this Long modulo the given one.

other {goog.math.Long}
Long by which to mod.
returns {!goog.math.Long}
This Long modulo the given one.

.multiply(other)

Returns the product of this and the given long.

other {goog.math.Long}
Long to multiply with this.
returns {!goog.math.Long}
The product of this and the other.

.negate()

returns {!goog.math.Long}
The negation of this value.

.not()

returns {!goog.math.Long}
The bitwise-NOT of this value.

.notEquals(other)

other {goog.math.Long}
Long to compare against.
returns {boolean}
Whether this Long does not equal the other.

.or(other)

Returns the bitwise-OR of this Long and the given one.

other {goog.math.Long}
The Long with which to OR.
returns {!goog.math.Long}
The bitwise-OR of this and the other.

.shiftLeft(numBits)

Returns this Long with bits shifted to the left by the given amount.

numBits {number}
The number of bits by which to shift.
returns {!goog.math.Long}
This shifted to the left by the given amount.

.shiftRight(numBits)

Returns this Long with bits shifted to the right by the given amount.

numBits {number}
The number of bits by which to shift.
returns {!goog.math.Long}
This shifted to the right by the given amount.

.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.

numBits {number}
The number of bits by which to shift.
returns {!goog.math.Long}
This shifted to the right by the given amount, with zeros placed into the new leading bits.

.subtract(other)

Returns the difference of this and the given Long.

other {goog.math.Long}
Long to subtract from this.
returns {!goog.math.Long}
The difference of this and the given Long.

.toInt()

returns {number}
The value, assuming it is a 32-bit integer.

.toNumber()

returns {number}
The closest floating-point representation to this value.

.toString(opt_radix)

opt_radix {number=}
The radix in which the text should be written.
returns {string}
The textual representation of this value.

.xor(other)

Returns the bitwise-XOR of this Long and the given one.

other {goog.math.Long}
The Long with which to XOR.
returns {!goog.math.Long}
The bitwise-XOR of this and the other.