|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Number | +--gishur.core.math.MathNumber | +--gishur.core.math.RationalNumber
A rational Number based upon MathNumber
. With rational numbers one
can perform exact arithmetic - to the cost of space and time.
A rational numbers stores a numerator()
and a denominator()
.
All arithmetic methods are supported - with the exception of
MathNumber.sqrt()
.
Fields inherited from class gishur.core.math.MathNumber |
MINUS_ONE, ONE, ZERO |
Constructor Summary | |
RationalNumber(java.math.BigInteger n,
java.math.BigInteger d)
|
|
RationalNumber(long n)
|
|
RationalNumber(long n,
long d)
|
Method Summary | |
MathNumber |
abs()
Computes |this|. |
MathNumber |
add(MathNumber n)
Computes this+ n . |
java.math.BigInteger |
denominator()
Returns the denominator of this rational number. |
MathNumber |
divide(MathNumber n)
Computes this/ n . |
double |
doubleValue()
Returns the value of the number as a double. |
MathNumber |
invert()
Computes 1/this. |
MathNumber |
multiply(MathNumber n)
Computes this* n . |
MathNumber |
negate()
Computes -this. |
void |
normalize()
Normalizes this fraction. |
java.math.BigInteger |
numerator()
Returns the numerator of this rational number. |
MathNumber |
pow(long n)
Computes this^ n . |
int |
sign()
Determines the sign of this number. |
MathNumber |
subtract(MathNumber n)
Computes this- n . |
Methods inherited from class gishur.core.math.MathNumber |
byteValue, compareTo, floatValue, intValue, log, longValue, max, min, shortValue, sqrt, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public RationalNumber(long n)
public RationalNumber(long n, long d)
public RationalNumber(java.math.BigInteger n, java.math.BigInteger d)
Method Detail |
public final void normalize()
ArithmeticException
- if the value of the denominator is
zero.MathNumberException
- if either or both of the arguments
are null
.public java.math.BigInteger numerator()
public java.math.BigInteger denominator()
public int sign()
sign
in class MathNumber
RationalNumber
public MathNumber abs()
abs
in class MathNumber
public MathNumber negate()
negate
in class MathNumber
public MathNumber invert()
invert
in class MathNumber
ArithmeticException
- if the value of this number is zero.public MathNumber add(MathNumber n)
n
.add
in class MathNumber
n
- the number to add to this.n
.MathNumberException
- if the operation does not support the
type of n
.public MathNumber subtract(MathNumber n)
n
.subtract
in class MathNumber
n
- the number to subtract from this.n
.MathNumberException
- if the operation does not support the
type of n
.public MathNumber multiply(MathNumber n)
n
.multiply
in class MathNumber
n
- the number to multiply this by.n
.MathNumberException
- if the operation does not support the
type of n
.public MathNumber divide(MathNumber n)
n
.divide
in class MathNumber
n
- the number to divide this by.n
.MathNumberException
- if the operation does not support the
type of n
.ArithmeticException
- if the argument is zero.public MathNumber pow(long n)
n
.pow
in class MathNumber
n
- the exponent.n
.MathNumberException
- if this Method is not supported
or if the argument is null
.public double doubleValue()
doubleValue
in class MathNumber
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |