math.Integer Extends
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.

Inheritance

Constructor

goog.math.Integer(bitssign)

Parameters

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

Instance Methods

Public Protected Private
add(other) !goog.math.Integer
Returns the sum of this and the given Integer.
Arguments:
other : goog.math.Integer
The Integer to add to this.
Returns: !goog.math.Integer  The Integer result.
code »
and(other) !goog.math.Integer
Returns the bitwise-AND of this Integer and the given one.
Arguments:
other : goog.math.Integer
The Integer to AND with this.
Returns: !goog.math.Integer  The bitwise-AND of this and the other.
code »
compare(other) number
Compares this Integer with the given one.
Arguments:
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.
code »
divide(other) !goog.math.Integer
Returns this Integer divided by the given one.
Arguments:
other : goog.math.Integer
Th Integer to divide this by.
Returns: !goog.math.Integer  This value divided by the given one.
code »
equals(other) boolean
No description.
Arguments:
other : goog.math.Integer
Integer to compare against.
Returns: boolean  Whether this Integer equals the other.
code »
getBits(index) number
Returns the index-th 32-bit (signed) piece of the Integer according to little-endian order (i.e., index 0 contains the smallest bits).
Arguments:
index : number
The index in question.
Returns: number  The requested 32-bits as a signed number.
code »
getBitsUnsigned(index) number
Returns the index-th 32-bit piece as an unsigned number.
Arguments:
index : number
The index in question.
Returns: number  The requested 32-bits as an unsigned number.
code »
getSign() number
No description.
Returns: number  The sign bit of this number, -1 or 0.
code »
greaterThan(other) boolean
No description.
Arguments:
other : goog.math.Integer
Integer to compare against.
Returns: boolean  Whether this Integer is greater than the other.
code »
greaterThanOrEqual(other) boolean
No description.
Arguments:
other : goog.math.Integer
Integer to compare against.
Returns: boolean  Whether this Integer is greater than or equal to the other.
code »
isNegative() boolean
No description.
Returns: boolean  Whether this value is negative.
code »
isOdd() boolean
No description.
Returns: boolean  Whether this value is odd.
code »
isZero() boolean
No description.
Returns: boolean  Whether this value is zero.
code »
lessThan(other) boolean
No description.
Arguments:
other : goog.math.Integer
Integer to compare against.
Returns: boolean  Whether this Integer is less than the other.
code »
lessThanOrEqual(other) boolean
No description.
Arguments:
other : goog.math.Integer
Integer to compare against.
Returns: boolean  Whether this Integer is less than or equal to the other.
code »
modulo(other) !goog.math.Integer
Returns this Integer modulo the given one.
Arguments:
other : goog.math.Integer
The Integer by which to mod.
Returns: !goog.math.Integer  This value modulo the given one.
code »
multiply(other) !goog.math.Integer
Returns the product of this and the given Integer.
Arguments:
other : goog.math.Integer
The Integer to multiply against this.
Returns: !goog.math.Integer  The product of this and the other.
code »
negate() !goog.math.Integer
No description.
Returns: !goog.math.Integer  The negation of this value.
code »
not() !goog.math.Integer
No description.
Returns: !goog.math.Integer  The bitwise-NOT of this value.
code »
notEquals(other) boolean
No description.
Arguments:
other : goog.math.Integer
Integer to compare against.
Returns: boolean  Whether this Integer does not equal the other.
code »
or(other) !goog.math.Integer
Returns the bitwise-OR of this Integer and the given one.
Arguments:
other : goog.math.Integer
The Integer to OR with this.
Returns: !goog.math.Integer  The bitwise-OR of this and the other.
code »
shiftLeft(numBits) !goog.math.Integer
Returns this value with bits shifted to the left by the given amount.
Arguments:
numBits : number
The number of bits by which to shift.
Returns: !goog.math.Integer  This shifted to the left by the given amount.
code »
shiftRight(numBits) !goog.math.Integer
Returns this value with bits shifted to the right by the given amount.
Arguments:
numBits : number
The number of bits by which to shift.
Returns: !goog.math.Integer  This shifted to the right by the given amount.
code »
shorten(numBits) !goog.math.Integer
Returns an integer with only the first numBits bits of this value, sign extended from the final bit.
Arguments:
numBits : number
The number of bits by which to shift.
Returns: !goog.math.Integer  The shorted integer value.
code »
subtract(other) !goog.math.Integer
Returns the difference of this and the given Integer.
Arguments:
other : goog.math.Integer
The Integer to subtract from this.
Returns: !goog.math.Integer  The Integer result.
code »
toInt() number
Returns the value, assuming it is a 32-bit integer.
Returns: number  The corresponding int value.
code »
toNumber() number
No description.
Returns: number  The closest floating-point representation to this value.
code »
toString(opt_radix) string
No description.
Arguments:
opt_radix : number=
The radix in which the text should be written.
Returns: string  The textual representation of this value.
code »
xor(other) !goog.math.Integer
Returns the bitwise-XOR of this Integer and the given one.
Arguments:
other : goog.math.Integer
The Integer to XOR with this.
Returns: !goog.math.Integer  The bitwise-XOR of this and the other.
code »

Instance Properties

bits_ :
No description.
Code »
sign_ :
No description.
Code »

Static Methods

goog.math.Integer.carry16_(bitsindex)
Carries any overflow from the given index into later entries.
Arguments:
bits : Array.<number>
Array of 16-bit values in little-endian order.
index : number
The index in question.
code »
goog.math.Integer.fromBits(bits) !goog.math.Integer
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.
Arguments:
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.
code »
goog.math.Integer.fromInt(value) !goog.math.Integer
Returns an Integer representing the given (32-bit) integer value.
Arguments:
value : number
A 32-bit integer value.
Returns: !goog.math.Integer  The corresponding Integer value.
code »
goog.math.Integer.fromNumber(value) !goog.math.Integer
Returns an Integer representing the given value, provided that it is a finite number. Otherwise, zero is returned.
Arguments:
value : number
The value in question.
Returns: !goog.math.Integer  The corresponding Integer value.
code »
goog.math.Integer.fromString(stropt_radix) !goog.math.Integer
Returns an Integer representation of the given string, written using the given radix.
Arguments:
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.
code »

Static Properties

goog.math.Integer.IntCache_ :
A cache of the Integer representations of small integer values.
Code »
goog.math.Integer.ONE : goog.math.Integer
No description.
Code »
goog.math.Integer.TWO_PWR_24_ : goog.math.Integer
No description.
Code »
goog.math.Integer.TWO_PWR_32_DBL_ :
A number used repeatedly in calculations. This must appear before the first call to the from* functions below.
Code »
goog.math.Integer.ZERO : goog.math.Integer
No description.
Code »

Package math

Package Reference