|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.spaceroots.mantissa.algebra.RationalNumber
This class implements reduced rational numbers.
Instances of this class are immutable.
| Field Summary | |
static RationalNumber |
ONE
One as a rational numer. |
static RationalNumber |
ZERO
Zero as a rational numer. |
| Constructor Summary | |
RationalNumber()
Simple constructor. |
|
RationalNumber(BigInteger i)
Simple constructor. |
|
RationalNumber(BigInteger numerator,
BigInteger denominator)
Simple constructor. |
|
RationalNumber(long l)
Simple constructor. |
|
RationalNumber(long numerator,
long denominator)
Simple constructor. |
|
| Method Summary | |
static RationalNumber |
abs(RationalNumber r)
Get the absolute value of a rational number. |
RationalNumber |
add(BigInteger l)
Add an integer to the instance. |
RationalNumber |
add(long l)
Add an integer to the instance. |
RationalNumber |
add(RationalNumber r)
Add a rational number to the instance. |
RationalNumber |
divide(BigInteger l)
Divide the instance by an integer. |
RationalNumber |
divide(long l)
Divide the instance by an integer. |
RationalNumber |
divide(RationalNumber r)
Divide the instance by a rational number. |
double |
doubleValue()
Return the double value of the instance. |
boolean |
equals(Object o)
Check if the instance is equal to another rational number. |
BigInteger |
getDenominator()
Get the denominator. |
BigInteger |
getNumerator()
Get the numerator. |
int |
hashCode()
Returns a hash code value for the object. |
RationalNumber |
invert()
Invert the instance. |
boolean |
isInteger()
Check if the number is integer. |
boolean |
isNegative()
Check if the number is negative. |
boolean |
isOne()
Check if the number is one. |
boolean |
isZero()
Check if the number is zero. |
RationalNumber |
multiply(BigInteger l)
Multiply the instance by an integer. |
RationalNumber |
multiply(long l)
Multiply the instance by an integer. |
RationalNumber |
multiply(RationalNumber r)
Multiply the instance by a rational number. |
RationalNumber |
negate()
Negate the instance. |
RationalNumber |
subtract(BigInteger l)
Subtract an integer from the instance. |
RationalNumber |
subtract(long l)
Subtract an integer from the instance. |
RationalNumber |
subtract(RationalNumber r)
Subtract a rational number from the instance. |
String |
toString()
Returns a string representation of the rational number. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final RationalNumber ZERO
public static final RationalNumber ONE
| Constructor Detail |
public RationalNumber()
public RationalNumber(long numerator,
long denominator)
numerator - numerator of the rational numberdenominator - denominator of the rational number
ArithmeticException - if the denominator is zero
public RationalNumber(BigInteger numerator,
BigInteger denominator)
numerator - numerator of the rational numberdenominator - denominator of the rational number
ArithmeticException - if the denominator is zeropublic RationalNumber(long l)
l - value of the rational numberpublic RationalNumber(BigInteger i)
i - value of the rational number| Method Detail |
public RationalNumber negate()
public RationalNumber add(long l)
l - integer to add
public RationalNumber add(BigInteger l)
l - integer to add
public RationalNumber add(RationalNumber r)
r - rational number to add
public RationalNumber subtract(long l)
l - integer to subtract
public RationalNumber subtract(BigInteger l)
l - integer to subtract
public RationalNumber subtract(RationalNumber r)
r - rational number to subtract
public RationalNumber multiply(long l)
l - integer to multiply by
public RationalNumber multiply(BigInteger l)
l - integer to multiply by
public RationalNumber multiply(RationalNumber r)
r - rational number to multiply the instance with
public RationalNumber divide(long l)
l - integer to divide by
ArithmeticException - if l is zeropublic RationalNumber divide(BigInteger l)
l - integer to divide by
ArithmeticException - if l is zeropublic RationalNumber divide(RationalNumber r)
r - rational number to divide by
ArithmeticException - if r is zeropublic RationalNumber invert()
ArithmeticException - if the instance is zeropublic BigInteger getNumerator()
public BigInteger getDenominator()
public boolean isZero()
public boolean isOne()
public boolean isInteger()
public boolean isNegative()
public static RationalNumber abs(RationalNumber r)
r - rational number from which we want the absolute value
public double doubleValue()
double value of the instance.
public boolean equals(Object o)
public int hashCode()
public String toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||