|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Number
com.dautelle.math.numbers.RealtimeNumber
com.dautelle.math.numbers.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.
Nested Class Summary | |
static class |
Rational.Value
This inner class represents a mutable image of an immutable Rational . |
Nested classes inherited from class com.dautelle.math.numbers.RealtimeNumber |
RealtimeNumber.Factory |
Field Summary | |
static Rational |
ONE
The Rational representing the multiplicative identity. |
static Rational |
ZERO
The Rational representing the additive identity. |
Method Summary | |
Rational |
abs()
Returns the absolute value of this Rational . |
Rational |
add(Rational that)
Returns the sum of this Rational with the one specified. |
java.lang.StringBuffer |
appendTo(java.lang.StringBuffer sb,
int radix)
Appends the text representation of this Rational to the
StringBuffer argument in the specified radix. |
int |
compareTo(java.lang.Object that)
Compares two Rational numerically. |
Rational |
divide(Rational that)
Returns this Rational divided by the one specified. |
double |
doubleValue()
Returns the value of this Rational as a double . |
boolean |
equals(java.lang.Object that)
Compares this Rational against the specified object. |
java.lang.Object |
export()
Exports this object out of the current pool context. |
float |
floatValue()
Returns the value of this Rational as a float . |
LargeInteger |
getDividend()
Returns the smallest dividend of the fraction representing this Rational . |
LargeInteger |
getDivisor()
Returns the smallest divisor of the fraction representing this Rational (always positive). |
int |
hashCode()
Returns the hash code for this Rational number. |
int |
intValue()
Returns the value of this Rational as an int . |
long |
longValue()
Returns the value of this Rational as a long . |
Rational |
multiply(Rational that)
Returns the product of this Rational with the one specified. |
Rational |
negate()
Returns the negation of this Rational . |
Operable |
opposite()
Returns the additive inverse of this object. |
Operable |
plus(Operable that)
Returns the sum of this object with the one specified. |
Operable |
reciprocal()
Returns the multiplicative inverse of this object. |
LargeInteger |
round()
Returns the closest Integer to this Rational . |
Rational |
subtract(Rational that)
Returns the difference between this Rational and the one
specified. |
Operable |
times(Operable that)
Returns the product of this object with the one specified. |
java.lang.Object |
toHeap()
Moves this object to the heap. |
java.lang.String |
toString()
Returns the decimal text representation of this Rational . |
java.lang.String |
toString(int radix)
Returns the text representation of this Rational in
the specified radix. |
void |
toXml(XmlElement xml)
Sets the attributes and content of the XML element corresponding to this object. |
static Rational |
valueOf(java.lang.CharSequence chars)
Returns the Rational for the specified character sequence. |
static Rational |
valueOf(LargeInteger dividend,
LargeInteger divisor)
Returns the Rational from the specified dividend and divisor. |
static Rational |
valueOf(XmlElement xml)
XML factory method. |
Methods inherited from class com.dautelle.math.numbers.RealtimeNumber |
clone, isLocalObject, isPoolObject, pow, recycle |
Methods inherited from class java.lang.Number |
byteValue, shortValue |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Rational ZERO
Rational
representing the additive identity.
public static final Rational ONE
Rational
representing the multiplicative identity.
Method Detail |
public static Rational valueOf(LargeInteger dividend, LargeInteger divisor)
Rational
from the specified dividend and 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)
Rational
for the specified character sequence.
chars
- the character sequence.
public static Rational valueOf(XmlElement xml)
xml
- the XML element describing the rational to return
(e.g. <math:Rational value="2/3"/>
).
valueOf(CharSequence)
public LargeInteger getDividend()
Rational
.
public LargeInteger getDivisor()
Rational
(always positive).
public LargeInteger round()
Integer
to this Rational
.
public Rational negate()
Rational
.
-this
.public Rational add(Rational that)
Rational
with the one specified.
that
- the Rational to be added.
this + that
.public Rational subtract(Rational that)
Rational
and the one
specified.
that
- the Rational to be subtracted.
this - that
.public Rational multiply(Rational that)
Rational
with the one specified.
that
- the Rational multiplier.
this * that
.public Rational divide(Rational that)
Rational
divided by the one specified.
that
- the Rational divisor.
this / that
.
java.lang.ArithmeticException
- if that.equals(ZERO)
public Rational abs()
Rational
.
abs(this)
.public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb, int radix)
Rational
to the
StringBuffer
argument in the specified radix.
sb
- the StringBuffer
to append.radix
- the radix of the representation.
StringBuffer
.public java.lang.String toString()
Rational
.
public java.lang.String toString(int radix)
Rational
in
the specified radix.
radix
- the radix of the representation.
public boolean equals(java.lang.Object that)
Rational
against the specified object.
that
- the object to compare with.
true
if the objects are the same;
false
otherwise.public int hashCode()
Rational
number.
public int intValue()
Rational
as an int
.
int
.public long longValue()
Rational
as a long
.
long
.public float floatValue()
Rational
as a float
.
float
.public double doubleValue()
Rational
as a double
.
double
.public int compareTo(java.lang.Object that)
Rational
numerically.
compareTo
in interface java.lang.Comparable
that
- the Rational to compare with.
that
.
java.lang.ClassCastException
- that
is not an Rational
.public Operable plus(Operable that)
Operable
plus
in interface Operable
that
- the object to be added.
this + that
.public Operable opposite()
Operable
this.plus(this.opposite()) == ZERO
,
with ZERO
being the additive identity.
opposite
in interface Operable
-this
.public Operable times(Operable that)
Operable
times
in interface Operable
that
- the object multiplier.
this * that
.public Operable reciprocal()
Operable
this.times(this.reciprocal()) == ONE
,
with ONE
being the multiplicative identity.
reciprocal
in interface Operable
ONE / this
.public void toXml(XmlElement xml)
Representable
toXml
in interface Representable
xml
- the XML element to set according to this object's desired XML
representation.public java.lang.Object export()
Realtime
Realtime
members are exported as well (recursion).
This method affects only objects belonging to the current pool context.
To avoid pool depletion, a "free" object from the outer pool
is moved to replace the object being exported.
export
in interface Realtime
export
in class RealtimeNumber
public java.lang.Object toHeap()
Realtime
Realtime
members are moved to the heap as well (recursion).
This method affects only objects belonging to a pool context
(current or not).
toHeap
in interface Realtime
toHeap
in class RealtimeNumber
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |