The goog.math.Integer Class

goog.math.Integer(bits, sign)

Constructs a two's-complement integer an array containing bits of the integer in 32-bit (signed) pieces, given in little-endian order (i.e., lowest-order bits in the first piece), and the sign of -1 or 0. See the from* functions below for other convenient ways of constructing Integers. The internal representation of an integer is an array of 32-bit signed pieces, along with a sign (0 or -1) that indicates the contents of all the other 32-bit pieces out to infinity. 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.

bits {Array.<number>}
Array containing the bits of the number.
sign {number}
The sign of the number: -1 for negative and 0 positive.

.ONE {!goog.math.Integer}

.ZERO {!goog.math.Integer}

.add(other)

Returns the sum of this and the given Integer.

other {goog.math.Integer}
The Integer to add to this.
returns {!goog.math.Integer}
The Integer result.

.and(other)

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

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

.compare(other)

Compares this Integer with the given one.

other {goog.math.Integer}
Integer 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.

.divide(other)

Returns this Integer divided by the given one.

other {goog.math.Integer}
Th Integer to divide this by.
returns {!goog.math.Integer}
This value divided by the given one.

.equals(other)

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

.fromBits(bits)

Returns a Integer representing the value that comes by concatenating the given entries, each is assumed to be 32 signed bits, given in little-endian order (lowest order bits in the lowest index), and sign-extending the highest order 32-bit value.

bits {Array.<number>}
The bits of the number, in 32-bit signed pieces, in little-endian order.
returns {!goog.math.Integer}
The corresponding Integer value.

.fromInt(value)

Returns an Integer representing the given (32-bit) integer value.

value {number}
A 32-bit integer value.
returns {!goog.math.Integer}
The corresponding Integer value.

.fromNumber(value)

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

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

.fromString(str, opt_radix)

Returns an Integer representation of the given string, written using the given radix.

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

.getBits(index)

Returns the index-th 32-bit (signed) piece of the Integer according to little-endian order (i.e., index 0 contains the smallest bits).

index {number}
The index in question.
returns {number}
The requested 32-bits as a signed number.

.getBitsUnsigned(index)

Returns the index-th 32-bit piece as an unsigned number.

index {number}
The index in question.
returns {number}
The requested 32-bits as an unsigned number.

.getSign()

returns {number}
The sign bit of this number, -1 or 0.

.greaterThan(other)

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

.greaterThanOrEqual(other)

other {goog.math.Integer}
Integer to compare against.
returns {boolean}
Whether this Integer 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.Integer}
Integer to compare against.
returns {boolean}
Whether this Integer is less than the other.

.lessThanOrEqual(other)

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

.modulo(other)

Returns this Integer modulo the given one.

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

.multiply(other)

Returns the product of this and the given Integer.

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

.negate()

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

.not()

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

.notEquals(other)

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

.or(other)

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

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

.shiftLeft(numBits)

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

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

.shiftRight(numBits)

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

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

.shorten(numBits)

Returns an integer with only the first numBits bits of this value, sign extended from the final bit.

numBits {number}
The number of bits by which to shift.
returns {!goog.math.Integer}
The shorted integer value.

.subtract(other)

Returns the difference of this and the given Integer.

other {goog.math.Integer}
The Integer to subtract from this.
returns {!goog.math.Integer}
The Integer result.

.toInt()

Returns the value, assuming it is a 32-bit integer.

returns {number}
The corresponding int value.

.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 Integer and the given one.

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