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(java.lang.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(java.lang.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, toString
public static Rational valueOf(long dividend, long divisor)
dividend
- the dividend value.divisor
- the divisor value.dividend / divisor
java.lang.ArithmeticException
- if divisor == 0
public static Rational valueOf(LargeInteger dividend, LargeInteger divisor)
dividend
- the dividend value.divisor
- the divisor value.dividend / divisor
java.lang.ArithmeticException
- if divisor.isZero()
public static Rational valueOf(java.lang.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
.java.lang.ArithmeticException
- if dividend.isZero()
public Rational divide(Rational that)
that
- the rational number divisor.this / that
.java.lang.ArithmeticException
- if that.equals(ZERO)
public boolean isZero()
this == 0
public boolean isPositive()
this > 0
public boolean isNegative()
this < 0
public 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(java.lang.Object that)
public int hashCode()
public long longValue()
long
.public double doubleValue()
double
.doubleValue
in class Number<Rational>
double
.