|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.lang.Number
|
+--org.metasyntactic.math.BigInteger
Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types). BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.
Semantics of arithmetic operations exactly mimic those of Java's integer arithmetic operators, as defined in The Java Language Specification. For example, division by zero throws an ArithmeticException, and division of a negative by a positive yields a negative (or zero) remainder. All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the results of an operation.
Semantics of shift operations extend those of Java's shift operators to allow for negative shift distances. A right-shift with a negative shift distance results in a left shift, and vice-versa. The unsigned right shift operator (>>>) is omitted, as this operation makes little sense in combination with the "infinite word size" abstraction provided by this class.
Semantics of bitwise logical operations exactly mimic those of Java's bitwise integer operators. The binary operators (and, or, xor) implicitly perform sign extension on the shorter of the two operands prior to performing the operation.
Comparison operations perform signed integer comparisons, analogous to those performed by Java's relational and equality operators.
Modular arithmetic operations are provided to compute residues, perform exponentiation, and compute multiplicative inverses. These methods always return a non-negative result, between 0 and (modulus - 1), inclusive.
Bit operations operate on a single bit of the two's-complement representation of their operand. If necessary, the operand is sign- extended so that it contains the designated bit. None of the single-bit operations can produce a BigInteger with a different sign from the BigInteger being operated on, as they affect only a single bit, and the infinite word size" abstraction provided by this class ensures that there are infinitely many "virtual sign bits" preceding each BigInteger.
For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigInteger methods. The pseudo-code expression (i + j) is shorthand for "a BigInteger whose value is that of the BigInteger i plus that of the BigInteger j. The pseudo-code expression (i == j) is shorthand for true if and only if the BigInteger i represents the same value as the the BigInteger j." Other pseudo-code expressions are interpreted similarly.
| Field Summary | |
static BigInteger |
ONE
|
static BigInteger |
ZERO
|
| Constructor Summary | |
BigInteger(boolean[] value)
|
|
BigInteger(boolean[] value,
boolean isNegative)
|
|
BigInteger(boolean[] value,
int start,
int finish,
boolean isNegative)
|
|
BigInteger(java.lang.String val)
|
|
BigInteger(java.lang.String val,
int radix)
|
|
| Method Summary | |
BigInteger |
abs()
|
BigInteger |
add(BigInteger bi)
Returns a BigInteger shose values is (this + bi) |
int |
bitCount()
|
int |
bitLength()
|
BigInteger |
clearBit(int n)
|
java.lang.Object |
clone()
|
int |
compareTo(BigInteger bi)
|
int |
compareTo(java.lang.Object o)
|
BigInteger |
copy()
|
BigInteger |
divide(BigInteger bi)
Returns a new BigInteger whose value is equals to (this / bi) |
BigInteger[] |
divideAndRemainder(BigInteger bi)
|
double |
doubleValue()
|
boolean |
equals(BigInteger bi)
|
boolean |
equals(java.lang.Object o)
|
BigInteger |
flipBit(int n)
|
float |
floatValue()
|
int |
getLowestSetBit()
|
int |
hashCode()
Returns a hashcode whose value is equals to (this % 231) |
int |
intValue()
|
boolean |
isZero()
|
long |
longValue()
|
static void |
main(java.lang.String[] args)
|
BigInteger |
max(BigInteger val)
|
BigInteger |
min(BigInteger val)
|
BigInteger |
multiply(BigInteger bi)
Returns a new BigInteger whose value is equal to (this * bi) |
BigInteger |
negate()
|
BigInteger |
not()
|
BigInteger |
pow(int exponent)
Returns a new BigInteger whose value is equal to (thisexponent) |
BigInteger |
remainder(BigInteger bi)
Returns a new BigInteger whose value is equal to (this % bi) |
BigInteger |
setBit(int n)
|
BigInteger |
shiftLeft(int places)
Returns a new BigInteger whose value is equal to (this << places)
NOTE! This method breaks the semantics of java's right shift operator in that
you can pass it a negative integer. |
BigInteger |
shiftRight(int places)
Returns a new BigInteger whose value is equal to (this >> places)
NOTE! This method breaks the semantics of java's right shift operator in that
you can pass it a negative integer. |
int |
signum()
|
BigInteger |
subtract(BigInteger bi)
Returns a BigInteger whose value is (this - bi) |
boolean |
testBit(int n)
|
java.lang.String |
toString()
Returns the String version of this BigInteger in base 10 format |
java.lang.String |
toString(int radix)
Returns the String version of this BigInteger in base radix
format. |
| Methods inherited from class java.lang.Number |
byteValue, shortValue |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final BigInteger ZERO
public static final BigInteger ONE
| Constructor Detail |
public BigInteger(java.lang.String val)
public BigInteger(java.lang.String val,
int radix)
public BigInteger(boolean[] value)
public BigInteger(boolean[] value,
boolean isNegative)
public BigInteger(boolean[] value,
int start,
int finish,
boolean isNegative)
| Method Detail |
public static void main(java.lang.String[] args)
public java.lang.Object clone()
clone in class java.lang.Objectpublic BigInteger copy()
public BigInteger add(BigInteger bi)
(this + bi)
bi - value to be added to this BigInteger
this + bipublic BigInteger subtract(BigInteger bi)
(this - bi)
bi - value to be subtracted from this BigInteger
this - bipublic BigInteger multiply(BigInteger bi)
(this * bi)
public BigInteger divide(BigInteger bi)
(this / bi)
java.lang.ArithmeticException - when bi == ZEROpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic boolean equals(BigInteger bi)
public int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparablepublic int compareTo(BigInteger bi)
public int hashCode()
(this % 231)
hashCode in class java.lang.Objectpublic BigInteger shiftRight(int places)
(this >> places)
NOTE! This method breaks the semantics of java's right shift operator in that
you can pass it a negative integer. If you pass it a negative integer then
this.shiftLeft(-places) will be called.
public BigInteger shiftLeft(int places)
(this << places)
NOTE! This method breaks the semantics of java's right shift operator in that
you can pass it a negative integer. If you pass it a negative integer then
this.shiftRight(-places) will be called.
public java.lang.String toString()
String version of this BigInteger in base 10 format
toString in class java.lang.Objectpublic java.lang.String toString(int radix)
String version of this BigInteger in base radix
format.
NOTE! While toString() is a costly method, the result is cached so that subsequent
calls to toString with the same radix will take almost no time
public BigInteger remainder(BigInteger bi)
(this % bi)
public BigInteger[] divideAndRemainder(BigInteger bi)
public BigInteger pow(int exponent)
(thisexponent)
public BigInteger abs()
public boolean isZero()
public BigInteger negate()
public int signum()
public BigInteger not()
public boolean testBit(int n)
public BigInteger setBit(int n)
public BigInteger clearBit(int n)
public BigInteger flipBit(int n)
public int getLowestSetBit()
public int bitLength()
public int bitCount()
public BigInteger min(BigInteger val)
public BigInteger max(BigInteger val)
public int intValue()
intValue in class java.lang.Numberpublic long longValue()
longValue in class java.lang.Numberpublic double doubleValue()
doubleValue in class java.lang.Numberpublic float floatValue()
floatValue in class java.lang.Number
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||