|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--EDU.ksu.cis.calculator.LargeInteger
A class which implements aribitrary-precision integer arithmetic. LargeIntegers are stored in any radix within the range 2-36, and radix conversions are done only when necessary; i.e., computations involving LargeIntegers of the same radix are done within that radix. Thus, if inputs and outputs are all to be in decimal, all of the computations are done in decimal, thereby saving expensive radix conversions.
Constructor Summary | |
LargeInteger(String s)
Constructs a new LargeInteger in base 10 from the given String. |
|
LargeInteger(String s,
int b)
Constructs a new LargeInteger in the given base from the given String. |
Method Summary | |
LargeInteger |
abs()
|
LargeInteger |
add(LargeInteger other)
Returns the sum of this LargeInteger and the given LargeInteger. |
int |
compareTo(Object o)
Compares this LargeInteger with the given Object. |
LargeInteger[] |
divide(int a)
Returns an array whose first element is this / a and whose second element is this % a. |
LargeInteger[] |
divide(LargeInteger other)
Returns a 2-element array whose first element is this / other and whose second element is this % other. |
int |
getBase()
|
LargeInteger |
multiply(int a)
Returns the product of this LargeInteger and a. |
LargeInteger |
multiply(LargeInteger other)
Returns the product of this LargeInteger and the given LargeInteger. |
LargeInteger |
negate()
Returns the LargeInteger obtained by changing the sign of this LargeInteger. |
LargeInteger |
pow(int exp)
Returns this LargeInteger raised to the power exp. |
static LargeInteger |
pow(int a,
int exp,
int db)
Returns the LargeInteger aexp, stored in base db. |
static LargeInteger |
pow(int a,
LargeInteger exp)
Returns a raised to the power exp. |
LargeInteger |
pow(LargeInteger other)
Returns this LargeInteger raised to the power other. |
LargeInteger |
subtract(LargeInteger other)
Returns the difference of this LargeInteger and the given LargeInteger. |
LargeInteger |
toBase(int b)
Converts this LargeInteger to the given base. |
String |
toString()
Returns the String representation of this LargeInteger. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public LargeInteger(String s) throws NumberFormatException
NumberFormatException
- if s does not encode a
decimal integer.public LargeInteger(String s, int b) throws NumberFormatException
NumberFormatException
- if s does not encode an
integer in the given base, or if the
given base is less than 2 or greater than
36.Method Detail |
public int compareTo(Object o) throws ClassCastException
compareTo
in interface Comparable
ClassCastException
- if the specified object is not a LargeInteger.public LargeInteger add(LargeInteger other)
public LargeInteger subtract(LargeInteger other)
public LargeInteger negate()
public LargeInteger multiply(LargeInteger other)
public LargeInteger[] divide(LargeInteger other) throws ArithmeticException
ArithmeticException
- if other is 0.public LargeInteger abs()
public LargeInteger toBase(int b) throws NumberFormatException
NumberFormatException
- If b < 2 or b > 36.public LargeInteger pow(LargeInteger other) throws ArithmeticException
ArithmeticException
- If other is negative.public LargeInteger pow(int exp) throws ArithmeticException
ArithmeticException
- If exp is negative.public static LargeInteger pow(int a, LargeInteger exp) throws ArithmeticException
ArithmeticException
- If exp is negative.public static LargeInteger pow(int a, int exp, int db) throws ArithmeticException
ArithmeticException
- If exp is negative.
NumberFormatException
- If db < 2 or db > 36public LargeInteger multiply(int a)
public LargeInteger[] divide(int a)
ArithmeticException
- If a = 0.public String toString()
Integer.toString(int)
, where the
given int is the radix associated with this LargeInteger.
toString
in class Object
public int getBase()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |