Home

# Class goog.math.Long

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.

Instance Method Summary
| `add(?goog.math.Long other) ⇒ !goog.math.Long` Returns the sum of this and the given Long.
| `and(?goog.math.Long other) ⇒ !goog.math.Long` Returns the bitwise-AND of this Long and the given one.
| `compare(?goog.math.Long other) ⇒ number` Compares this Long with the given one.
| `div(?goog.math.Long other) ⇒ !goog.math.Long` Returns this Long divided by the given one.
| `equals(?goog.math.Long other) ⇒ boolean`
| `getHighBits() ⇒ number`
| `getLowBits() ⇒ number`
| `getLowBitsUnsigned() ⇒ number`
| `getNumBitsAbs() ⇒ number`
| `greaterThan(?goog.math.Long other) ⇒ boolean`
| `greaterThanOrEqual(?goog.math.Long other) ⇒ boolean`
| `isNegative() ⇒ boolean`
| `isOdd() ⇒ boolean`
| `isZero() ⇒ boolean`
| `lessThan(?goog.math.Long other) ⇒ boolean`
| `lessThanOrEqual(?goog.math.Long other) ⇒ boolean`
| `modulo(?goog.math.Long other) ⇒ !goog.math.Long` Returns this Long modulo the given one.
| `multiply(?goog.math.Long other) ⇒ !goog.math.Long` Returns the product of this and the given long.
| `negate() ⇒ !goog.math.Long`
| `not() ⇒ !goog.math.Long`
| `notEquals(?goog.math.Long other) ⇒ boolean`
| `or(?goog.math.Long other) ⇒ !goog.math.Long` Returns the bitwise-OR of this Long and the given one.
| `shiftLeft(number numBits) ⇒ !goog.math.Long` Returns this Long with bits shifted to the left by the given amount.
| `shiftRight(number numBits) ⇒ !goog.math.Long` Returns this Long with bits shifted to the right by the given amount.
| `shiftRightUnsigned(number numBits) ⇒ !goog.math.Long` Returns this Long with bits shifted to the right by the given amount, with the new top bits matching the current sign bit.
| `subtract(?goog.math.Long other) ⇒ !goog.math.Long` Returns the difference of this and the given Long.
| `toInt() ⇒ number`
| `toNumber() ⇒ number`
| `toString(number= opt_radix) ⇒ string`
| `xor(?goog.math.Long other) ⇒ !goog.math.Long` Returns the bitwise-XOR of this Long and the given one.

Static Method Summary
| `fromBits(number lowBits, number highBits) ⇒ !goog.math.Long` 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.
| `fromInt(number value) ⇒ !goog.math.Long` Returns a Long representing the given (32-bit) integer value.
| `fromNumber(number value) ⇒ !goog.math.Long` Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
| `fromString(string str, number= opt_radix) ⇒ !goog.math.Long` Returns a Long representation of the given string, written using the given radix.