Package org.jscience.mathematics.number
Class Rational
- All Implemented Interfaces:
Serializable
,Comparable<Rational>
,javolution.lang.Immutable
,javolution.lang.Realtime
,javolution.lang.ValueType
,javolution.xml.XMLSerializable
,Field<Rational>
,GroupAdditive<Rational>
,GroupMultiplicative<Rational>
,Ring<Rational>
,Structure<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.
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionabs()
Returns the absolute value of this rational number.int
Compares two rational number numerically.copy()
Returns a copy of this numberallocated
by the calling thread (possibly on the stack).Returns this rational number divided by the one specified.double
Returns the value of this rational number as adouble
.boolean
Compares this rational number against the specified object.Returns the smallest dividend of the fraction representing this rational number.Returns the smallest divisor of the fraction representing this rational (always positive).int
hashCode()
Returns the hash code for this rational number.inverse()
Returns the inverse of this rational number.boolean
isLargerThan
(Rational that) Compares the absolute value of two rational numbers.boolean
Indicates if this rational number is less than zero.boolean
Indicates if this rational number is greater than zero.boolean
isZero()
Indicates if this rational number is equal to zero.long
Returns the value of this rational number as along
.Returns the difference between this rational number and the one specified.opposite()
Returns the opposite of this rational number.Returns the sum of this rational number with the one specified.round()
Returns the closest integer value to this rational number.times
(long multiplier) Returns the product of this rational number with the specifiedlong
multiplier.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
(long dividend, long divisor) Returns the rational number for the specified integer dividend and divisor.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.Methods inherited from class org.jscience.mathematics.number.Number
byteValue, floatValue, intValue, isGreaterThan, isLessThan, pow, shortValue, toString
-
Field Details
-
Method Details
-
valueOf
Returns the rational number for the specified integer dividend and divisor.- Parameters:
dividend
- the dividend value.divisor
- the divisor value.- Returns:
dividend / divisor
- Throws:
ArithmeticException
- ifdivisor == 0
-
valueOf
Returns the rational number for the specified large integer dividend and divisor.- Parameters:
dividend
- the dividend value.divisor
- the divisor value.- Returns:
dividend / divisor
- Throws:
ArithmeticException
- ifdivisor.isZero()
-
valueOf
Returns the rational number for the specified character sequence.- Parameters:
chars
- the character sequence.- Returns:
- the corresponding rational number.
-
getDividend
Returns the smallest dividend of the fraction representing this rational number.- Returns:
- this rational dividend.
-
getDivisor
Returns the smallest divisor of the fraction representing this rational (always positive).- Returns:
- this rational divisor.
-
round
Returns the closest integer value to this rational number.- Returns:
- this rational rounded to the nearest integer.
-
opposite
Returns the opposite of this rational number.- Specified by:
opposite
in interfaceGroupAdditive<Rational>
- Returns:
-this
.
-
plus
Returns the sum of this rational number with the one specified.- Specified by:
plus
in interfaceGroupAdditive<Rational>
- Parameters:
that
- the rational number to be added.- Returns:
this + that
.
-
minus
Returns the difference between this rational number and the one specified. -
times
Returns the product of this rational number with the specifiedlong
multiplier.- Parameters:
multiplier
- thelong
multiplier.- Returns:
this · multiplier
.
-
times
Returns the product of this rational number with the one specified. -
inverse
Returns the inverse of this rational number.- Specified by:
inverse
in interfaceGroupMultiplicative<Rational>
- Returns:
1 / this
.- Throws:
ArithmeticException
- ifdividend.isZero()
-
divide
Returns this rational number divided by the one specified.- Parameters:
that
- the rational number divisor.- Returns:
this / that
.- Throws:
ArithmeticException
- ifthat.equals(ZERO)
-
abs
Returns the absolute value of this rational number.- Returns:
|this|
.
-
isZero
public boolean isZero()Indicates if this rational number is equal to zero.- Returns:
this == 0
-
isPositive
public boolean isPositive()Indicates if this rational number is greater than zero.- Returns:
this > 0
-
isNegative
public boolean isNegative()Indicates if this rational number is less than zero.- Returns:
this < 0
-
isLargerThan
Compares the absolute value of two rational numbers.- Specified by:
isLargerThan
in classNumber<Rational>
- Parameters:
that
- the rational number to be compared with.- Returns:
|this| > |that|
-
toText
public javolution.text.Text toText()Returns the decimal text representation of this number. -
equals
Compares this rational number against the specified object. -
hashCode
public int hashCode()Returns the hash code for this rational number. -
longValue
public long longValue()Returns the value of this rational number as along
. -
doubleValue
public double doubleValue()Returns the value of this rational number as adouble
.- Specified by:
doubleValue
in classNumber<Rational>
- Returns:
- the numeric value represented by this rational after conversion
to type
double
.
-
compareTo
Compares two rational number numerically. -
copy
Description copied from class:Number
Returns a copy of this numberallocated
by the calling thread (possibly on the stack).
-