public final class Rational extends Number<Rational> implements Field<Rational>
This class represents the ratio of two LargeInteger numbers.
Instances of this class are immutable and can be used to find exact
solutions to linear equations with the Matrix class.
| Modifier and Type | Field and Description |
|---|---|
static Rational |
ONE
The
Rational representing the multiplicative identity. |
static Rational |
ZERO
The
Rational representing the additive identity. |
| Modifier and Type | Method and Description |
|---|---|
Rational |
abs()
Returns the absolute value of this rational number.
|
int |
compareTo(Rational that)
Compares two rational number numerically.
|
Rational |
copy()
Returns a copy of this number
allocated
by the calling thread (possibly on the stack). |
Rational |
divide(Rational that)
Returns this rational number divided by the one specified.
|
double |
doubleValue()
Returns the value of this rational number as a
double. |
boolean |
equals(Object that)
Compares this rational number against the specified object.
|
LargeInteger |
getDividend()
Returns the smallest dividend of the fraction representing this
rational number.
|
LargeInteger |
getDivisor()
Returns the smallest divisor of the fraction representing this
rational (always positive).
|
int |
hashCode()
Returns the hash code for this rational number.
|
Rational |
inverse()
Returns the inverse of this rational number.
|
boolean |
isLargerThan(Rational that)
Compares the absolute value of two rational numbers.
|
boolean |
isNegative()
Indicates if this rational number is less than zero.
|
boolean |
isPositive()
Indicates if this rational number is greater than zero.
|
boolean |
isZero()
Indicates if this rational number is equal to zero.
|
long |
longValue()
Returns the value of this rational number as a
long. |
Rational |
minus(Rational that)
Returns the difference between this rational number and the one
specified.
|
Rational |
opposite()
Returns the opposite of this rational number.
|
Rational |
plus(Rational that)
Returns the sum of this rational number with the one specified.
|
LargeInteger |
round()
Returns the closest integer value to this rational number.
|
Rational |
times(long multiplier)
Returns the product of this rational number with the specified
long multiplier. |
Rational |
times(Rational that)
Returns the product of this rational number with the one specified.
|
javolution.text.Text |
toText()
Returns the decimal text representation of this number.
|
static Rational |
valueOf(CharSequence chars)
Returns the rational number for the specified character sequence.
|
static Rational |
valueOf(LargeInteger dividend,
LargeInteger divisor)
Returns the rational number for the specified large integer
dividend and divisor.
|
static Rational |
valueOf(long dividend,
long divisor)
Returns the rational number for the specified integer dividend and
divisor.
|
byteValue, floatValue, intValue, isGreaterThan, isLessThan, pow, shortValue, toStringpublic static Rational valueOf(long dividend, long divisor)
dividend - the dividend value.divisor - the divisor value.dividend / divisorArithmeticException - if divisor == 0public static Rational valueOf(LargeInteger dividend, LargeInteger divisor)
dividend - the dividend value.divisor - the divisor value.dividend / divisorArithmeticException - if divisor.isZero()public static Rational valueOf(CharSequence chars)
chars - the character sequence.public LargeInteger getDividend()
public LargeInteger getDivisor()
public LargeInteger round()
public Rational opposite()
opposite in interface GroupAdditive<Rational>-this.public Rational plus(Rational that)
plus in interface GroupAdditive<Rational>that - the rational number to be added.this + that.public Rational minus(Rational that)
public Rational times(long multiplier)
long multiplier.multiplier - the long multiplier.this · multiplier.public Rational times(Rational that)
public Rational inverse()
inverse in interface GroupMultiplicative<Rational>1 / this.ArithmeticException - if dividend.isZero()public Rational divide(Rational that)
that - the rational number divisor.this / that.ArithmeticException - if that.equals(ZERO)public Rational abs()
|this|.public boolean isZero()
this == 0public boolean isPositive()
this > 0public boolean isNegative()
this < 0public boolean isLargerThan(Rational that)
isLargerThan in class Number<Rational>that - the rational number to be compared with.|this| > |that|public javolution.text.Text toText()
public boolean equals(Object that)
public int hashCode()
public long longValue()
long.public double doubleValue()
double.doubleValue in class Number<Rational>double.public int compareTo(Rational that)