| Package | org.granite.math |
| Class | public final class BigInteger |
| Implements | BigNumber |
int type). BigInteger provides analogues
to all of ActionScript3's primitive integer operators (+, -, *, /).
BigNumberError, and division of a negative by a positive yields a
negative (or zero) remainder. All of the details concerning overflow are ignored, as
BigIntegers are made as large as necessary to accommodate the results
of an operation.
java.math.BigInteger originally written by
Josh Bloch and Michael McCloskey, but relies on a completely different
implementation. It provides externalization methods that are
meant to be used with specific GraniteDS serialization mechanisms.
See also
| Property | Defined by | ||
|---|---|---|---|
| sign : int [read-only]
The sign of this
BigInteger as an int, ie:
-1, 0 or 1 as the value of this BigInteger is negative,
zero or positive. | BigInteger | ||
| Method | Defined by | ||
|---|---|---|---|
|
BigInteger(value:* = null, radix:int = 10)
Constructs a new
BigInteger instance according to the
supplied parameters. | BigInteger | ||
|
Returns a
BigInteger whose value is the absolute value
of this BigInteger. | BigInteger | ||
|
add(b:*):BigInteger
Returns a
BigInteger whose value is (this + b). | BigInteger | ||
| BigInteger | |||
|
compareTo(b:BigInteger, unsigned:Boolean = false):int
Compares this
BigInteger with the specified
BigInteger. | BigInteger | ||
|
divide(b:*):BigInteger
Returns a
BigInteger whose value is (this / b). | BigInteger | ||
|
divideAndRemainder(b:*):Array
Returns an array of two
BigInteger containing
(this / b) followed by (this % b). | BigInteger | ||
|
equals(b:*):Boolean
Compares this
BigInteger with the specified object
for equality. | BigInteger | ||
|
max(b:*):BigInteger
Returns the maximum of this
BigInteger and
b. | BigInteger | ||
|
min(b:*):BigInteger
Returns the minimum of this
BigInteger and
b. | BigInteger | ||
|
multiply(b:*):BigInteger
Returns a
BigInteger whose value is (this * b). | BigInteger | ||
|
Returns a
BigInteger whose value is (-this). | BigInteger | ||
|
remainder(b:*):BigInteger
Returns a
BigInteger whose value is (this % b). | BigInteger | ||
|
subtract(b:*):BigInteger
Returns a
BigInteger whose value is (this - b). | BigInteger | ||
|
toInt():int
Converts this
BigInteger to an int: if this
BigInteger is too big to fit in an int,
only the low-order 31 bits are returned and the sign of the result is
preserved as it was in the orginal BigInteger. | BigInteger | ||
|
toNumber():Number
Converts this
BigInteger to a Number. | BigInteger | ||
|
toString(radix:int = 10, abs:Boolean = false):String
Returns the String representation of this
BigInteger in the
given radix. | BigInteger | ||
| Constant | Defined by | ||
|---|---|---|---|
| ONE : BigInteger
[static]
The
BigInteger constant one. | BigInteger | ||
| TEN : BigInteger
[static]
The
BigInteger constant ten. | BigInteger | ||
| ZERO : BigInteger
[static]
The
BigInteger constant zero. | BigInteger | ||
| sign | property |
sign:int [read-only]
The sign of this BigInteger as an int, ie:
-1, 0 or 1 as the value of this BigInteger is negative,
zero or positive.
public function get sign():int
| BigInteger | () | constructor |
public function BigInteger(value:* = null, radix:int = 10)
Constructs a new BigInteger instance according to the
supplied parameters.
The value parameter may be a String representation of
an integer, a int primitive value, a Number
or even another BigInteger:
String: it must be a not empty String in the form of
-?[0-9a-zA-Z]+ (ie: an optional '-' character followed by
a not empty sequence of digits (with radix >= 2 and <= 36)). When
a String value is used, the second parameter radix
is also used, and the supplied digits must be in accordance with
the specified radix.int: a primitive integer value (radix ignored).Number: a primitive number value (radix ignored). Only
the fixed part of the number will be used (decimal part is
ignored).Long: the new BigInteger will be equals to
the specified parameter.BigInteger: the new BigInteger will be an exact copy of
the specified parameter.null: the new BigInteger will be an exact copy of
the constant BigInteger.ZERO.value:* (default = null) — the value to be assigned to the new BigInteger.
|
|
radix:int (default = 10) — the radix (2 <= radix <= 36) to be used for string conversion
(ignored if the value parameter isn't a string).
|
NumberFormatError — if the value
parameter is an invalid String representation.
|
|
IllegalArgumentError — if the value
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
| abs | () | method |
public function abs():BigInteger
Returns a BigInteger whose value is the absolute value
of this BigInteger.
BigInteger —
the absolute value of this BigInteger.
|
| add | () | method |
public function add(b:*):BigInteger
Returns a BigInteger whose value is (this + b).
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — b the value to be added to this BigInteger.
|
BigInteger —
(this + b).
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| clone | () | method |
| compareTo | () | method |
public function compareTo(b:BigInteger, unsigned:Boolean = false):int
Compares this BigInteger with the specified
BigInteger. This method is provided in preference to
individual methods for each of the six boolean comparison operators
(<, ==, >, <=, !=, >=). The suggested idiom for performing
these comparisons is: (x.compareTo(y) <op> 0),
where <op> is one of the six comparison operators.
b:BigInteger — the BigInteger to which this BigInteger
is to be compared.
|
|
unsigned:Boolean (default = false) — if true, the comparison is made between absolute
values (ie: this.abs().compareTo(b.abs())).
|
int — -1, 0 or 1 as this BigInteger is numerically less than,
equal to, or greater than b.
|
| divide | () | method |
public function divide(b:*):BigInteger
Returns a BigInteger whose value is (this / b).
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — b the value by which this BigInteger is to be divided.
|
BigInteger —
(this / b).
|
ArithmeticError — if the b
parameter is equals to 0.
|
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| divideAndRemainder | () | method |
public function divideAndRemainder(b:*):Array
Returns an array of two BigInteger containing
(this / b) followed by (this % b).
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — b the value by which this BigInteger is to be divided,
and the remainder computed.
|
Array — an array of two BigIntegers: the quotient (this / val)
is the initial element, and the remainder (this % val)
is the final element.
|
ArithmeticError — if the b
parameter is equals to 0.
|
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| equals | () | method |
public function equals(b:*):Boolean
Compares this BigInteger with the specified object
for equality.
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — an object to which this BigInteger is to
be compared.
|
Boolean — true if and only if the specified object is
a BigInteger (or convertible to a
BigInteger) whose value is numerically equal
to this BigInteger.
|
See also
| max | () | method |
public function max(b:*):BigInteger
Returns the maximum of this BigInteger and
b.
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — the value with which the maximum is to be computed.
|
BigInteger —
the BigInteger whose value is the greater of
this BigInteger and b. If they are
equal, either may be returned.
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| min | () | method |
public function min(b:*):BigInteger
Returns the minimum of this BigInteger and
b.
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — the value with which the minimum is to be computed.
|
BigInteger —
the BigInteger whose value is the lesser of
this BigInteger and b. If they are
equal, either may be returned.
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| multiply | () | method |
public function multiply(b:*):BigInteger
Returns a BigInteger whose value is (this * b).
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — b the value to be multiplied by this BigInteger.
|
BigInteger —
(this * b).
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| negate | () | method |
public function negate():BigInteger
Returns a BigInteger whose value is (-this).
BigInteger —
(-this).
|
| remainder | () | method |
public function remainder(b:*):BigInteger
Returns a BigInteger whose value is (this % b).
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — b the value by which this BigInteger is to be divided,
and the remainder computed.
|
BigInteger —
(this % b).
|
ArithmeticError — if the b
parameter is equals to 0.
|
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| subtract | () | method |
public function subtract(b:*):BigInteger
Returns a BigInteger whose value is (this - b).
The b parameter may be of any of the supported types as
specified in the BigInteger constructor documentation
(a radix of 10 is assumed for String representations).
b:* — b the value to be subtracted from this BigInteger.
|
BigInteger —
(this - b).
|
NumberFormatError — if the b
parameter is an invalid String representation (for radix 10).
|
|
IllegalArgumentError — if the b
parameter is not one of the supported types or if it is
Number.NaN, Number.POSITIVE_INFINITY or
Number.NEGATIVE_INFINITY.
|
See also
| toInt | () | method |
public function toInt():int
Converts this BigInteger to an int: if this
BigInteger is too big to fit in an int,
only the low-order 31 bits are returned and the sign of the result is
preserved as it was in the orginal BigInteger.
Note this conversion is slightly different than the Java one: it
always preserves the sign and conforms to following rules:
this < int.MIN_VALUE, then int.MIN_VALUE
is returned.int.MIN_VALUE <= this <= int.MAX_VALUE,
then int(this) is returned (exact result).this > int.MAX_VALUE, then int.MAX_VALUE
is returned.int — this BigInteger converted to an int.
|
| toNumber | () | method |
public function toNumber():Number
Converts this BigInteger to a Number. This
conversion is done by converting this BigInteger to signed
String representation and constructing a new Number from
this representation: if this BigInteger has atoo great
magnitude to be represented as a Number, it will be converted to
Number.NEGATIVE_INFINITY or Number.POSITIVE_INFINITY
as appropriate. Note that even when the return value is finite, this
conversion can lose information about the precision of the
BigInteger value.
Number — this BigInteger converted to a Number.
|
| toString | () | method |
public function toString(radix:int = 10, abs:Boolean = false):String
Returns the String representation of this BigInteger in the
given radix. If the radix is outside the range from 2 to 36 inclusive,
an error is thrown. The digit-to-character mapping uses "0...9, a...z"
characters, and a minus sign is prepended if appropriate.
radix:int (default = 10) — the radix of the String representation.
|
|
abs:Boolean (default = false) — if true, the minus sign is skipped even if this
BigInteger is negative.
|
String — String representation of this BigInteger in the given
radix.
|
See also
| ONE | constant |
public static const ONE:BigInteger
The BigInteger constant one.
| TEN | constant |
public static const TEN:BigInteger
The BigInteger constant ten.
| ZERO | constant |
public static const ZERO:BigInteger
The BigInteger constant zero.