\n\n\n\nRational\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n\n
\n
org.jscience.mathematics.number
\n

## Class Rational

\n
\n
\n
\n
\n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Field Summary

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Fields
Modifier and TypeField and Description
`static Rational``ONE`\n
The `Rational` representing the multiplicative identity.
\n
`static Rational``ZERO`\n
The `Rational` representing the additive identity.
\n
\n
• \n
\n\n
\n
• \n\n\n

### Method Summary

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Methods
Modifier and TypeMethod and Description
`Rational``abs()`\n
Returns the absolute value of this rational number.
\n
`int``compareTo(Rational that)`\n
Compares two rational number numerically.
\n
`Rational``copy()`\n
Returns a copy of this number \n `allocated` \n by the calling thread (possibly on the stack).
\n
`Rational``divide(Rational that)`\n
Returns this rational number divided by the one specified.
\n
`double``doubleValue()`\n
Returns the value of this rational number as a `double`.
\n
`boolean``equals(Object that)`\n
Compares this rational number against the specified object.
\n
`LargeInteger``getDividend()`\n
Returns the smallest dividend of the fraction representing this\n rational number.
\n
`LargeInteger``getDivisor()`\n
Returns the smallest divisor of the fraction representing this \n rational (always positive).
\n
`int``hashCode()`\n
Returns the hash code for this rational number.
\n
`Rational``inverse()`\n
Returns the inverse of this rational number.
\n
`boolean``isLargerThan(Rational that)`\n
Compares the absolute value of two rational numbers.
\n
`boolean``isNegative()`\n
Indicates if this rational number is less than zero.
\n
`boolean``isPositive()`\n
Indicates if this rational number is greater than zero.
\n
`boolean``isZero()`\n
Indicates if this rational number is equal to zero.
\n
`long``longValue()`\n
Returns the value of this rational number as a `long`.
\n
`Rational``minus(Rational that)`\n
Returns the difference between this rational number and the one\n specified.
\n
`Rational``opposite()`\n
Returns the opposite of this rational number.
\n
`Rational``plus(Rational that)`\n
Returns the sum of this rational number with the one specified.
\n
`LargeInteger``round()`\n
Returns the closest integer value to this rational number.
\n
`Rational``times(long multiplier)`\n
Returns the product of this rational number with the specified \n `long` multiplier.
\n
`Rational``times(Rational that)`\n
Returns the product of this rational number with the one specified.
\n
`javolution.text.Text``toText()`\n
Returns the decimal text representation of this number.
\n
`static Rational``valueOf(CharSequence chars)`\n
Returns the rational number for the specified character sequence.
\n
`static Rational``valueOf(LargeInteger dividend,\n LargeInteger divisor)`\n
Returns the rational number for the specified large integer \n dividend and divisor.
\n
`static Rational``valueOf(long dividend,\n long divisor)`\n
Returns the rational number for the specified integer dividend and \n divisor.
\n
\n
\n
• \n\n\n

### Methods inherited from class org.jscience.mathematics.number.Number

\n`byteValue, floatValue, intValue, isGreaterThan, isLessThan, pow, shortValue, toString`
• \n
\n
\n
• \n\n\n

### Methods inherited from class java.lang.Object

\n`getClass, notify, notifyAll, wait, wait, wait`
• \n
\n
• \n
\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Field Detail

\n\n\n\n
\n
• \n

#### ZERO

\n
`public static final Rational ZERO`
\n
The `Rational` representing the additive identity.
\n
• \n
\n\n\n\n
\n
• \n

#### ONE

\n
`public static final Rational ONE`
\n
The `Rational` representing the multiplicative identity.
\n
• \n
\n
• \n
\n\n
\n
• \n\n\n

### Method Detail

\n\n\n\n
\n
• \n

#### valueOf

\n
`public static Rational valueOf(long dividend,\n               long divisor)`
\n
Returns the rational number for the specified integer dividend and \n divisor.
\n
Parameters:
`dividend` - the dividend value.
`divisor` - the divisor value.
\n
Returns:
`dividend / divisor`
\n
Throws:
\n
`ArithmeticException` - if `divisor == 0`
\n
• \n
\n\n\n\n
\n
• \n

#### valueOf

\n
`public static Rational valueOf(LargeInteger dividend,\n               LargeInteger divisor)`
\n
Returns the rational number for the specified large integer \n dividend and divisor.
\n
Parameters:
`dividend` - the dividend value.
`divisor` - the divisor value.
\n
Returns:
`dividend / divisor`
\n
Throws:
\n
`ArithmeticException` - if `divisor.isZero()`
\n
• \n
\n\n\n\n
\n
• \n

#### valueOf

\n
`public static Rational valueOf(CharSequence chars)`
\n
Returns the rational number for the specified character sequence.
\n
Parameters:
`chars` - the character sequence.
\n
Returns:
the corresponding rational number.
\n
• \n
\n\n\n\n
\n
• \n

#### getDividend

\n
`public LargeInteger getDividend()`
\n
Returns the smallest dividend of the fraction representing this\n rational number.
\n
Returns:
this rational dividend.
\n
• \n
\n\n\n\n
\n
• \n

#### getDivisor

\n
`public LargeInteger getDivisor()`
\n
Returns the smallest divisor of the fraction representing this \n rational (always positive).
\n
Returns:
this rational divisor.
\n
• \n
\n\n\n\n
\n
• \n

#### round

\n
`public LargeInteger round()`
\n
Returns the closest integer value to this rational number.
\n
Returns:
this rational rounded to the nearest integer.
\n
• \n
\n\n\n\n
\n
• \n

#### opposite

\n
`public Rational opposite()`
\n
Returns the opposite of this rational number.
\n
\n
Specified by:
\n
`opposite` in interface `GroupAdditive<Rational>`
\n
Returns:
`-this`.
\n
• \n
\n\n\n\n
\n
• \n

#### plus

\n
`public Rational plus(Rational that)`
\n
Returns the sum of this rational number with the one specified.
\n
\n
Specified by:
\n
`plus` in interface `GroupAdditive<Rational>`
\n
Parameters:
`that` - the rational number to be added.
\n
Returns:
`this + that`.
\n
• \n
\n\n\n\n
\n
• \n

#### minus

\n
`public Rational minus(Rational that)`
\n
Returns the difference between this rational number and the one\n specified.
\n
\n
Overrides:
\n
`minus` in class `Number<Rational>`
\n
Parameters:
`that` - the rational number to be subtracted.
\n
Returns:
`this - that`.
\n
• \n
\n\n\n\n
\n
• \n

#### times

\n
`public Rational times(long multiplier)`
\n
Returns the product of this rational number with the specified \n `long` multiplier.
\n
Parameters:
`multiplier` - the `long` multiplier.
\n
Returns:
`this \xc2\xb7 multiplier`.
\n
• \n
\n\n\n\n
\n
• \n

#### times

\n
`public Rational times(Rational that)`
\n
Returns the product of this rational number with the one specified.
\n
\n
Specified by:
\n
`times` in interface `GroupMultiplicative<Rational>`
\n
Specified by:
\n
`times` in interface `Ring<Rational>`
\n
Parameters:
`that` - the rational number multiplier.
\n
Returns:
`this \xc2\xb7 that`.
\n
• \n
\n\n\n\n
\n
• \n

#### inverse

\n
`public Rational inverse()`
\n
Returns the inverse of this rational number.
\n
\n
Specified by:
\n
`inverse` in interface `GroupMultiplicative<Rational>`
\n
Returns:
`1 / this`.
\n
Throws:
\n
`ArithmeticException` - if `dividend.isZero()`
\n
• \n
\n\n\n\n
\n
• \n

#### divide

\n
`public Rational divide(Rational that)`
\n
Returns this rational number divided by the one specified.
\n
Parameters:
`that` - the rational number divisor.
\n
Returns:
`this / that`.
\n
Throws:
\n
`ArithmeticException` - if `that.equals(ZERO)`
\n
• \n
\n\n\n\n
\n
• \n

#### abs

\n
`public Rational abs()`
\n
Returns the absolute value of this rational number.
\n
Returns:
`|this|`.
\n
• \n
\n\n\n\n
\n
• \n

#### isZero

\n
`public boolean isZero()`
\n
Indicates if this rational number is equal to zero.
\n
Returns:
`this == 0`
\n
• \n
\n\n\n\n
\n
• \n

#### isPositive

\n
`public boolean isPositive()`
\n
Indicates if this rational number is greater than zero.
\n
Returns:
`this > 0`
\n
• \n
\n\n\n\n
\n
• \n

#### isNegative

\n
`public boolean isNegative()`
\n
Indicates if this rational number is less than zero.
\n
Returns:
`this < 0`
\n
• \n
\n\n\n\n
\n
• \n

#### isLargerThan

\n
`public boolean isLargerThan(Rational that)`
\n
Compares the absolute value of two rational numbers.
\n
\n
Specified by:
\n
`isLargerThan` in class `Number<Rational>`
\n
Parameters:
`that` - the rational number to be compared with.
\n
Returns:
`|this| > |that|`
\n
• \n
\n\n\n\n
\n
• \n

#### toText

\n
`public javolution.text.Text toText()`
\n
Returns the decimal text representation of this number.
\n
\n
Specified by:
\n
`toText` in interface `javolution.lang.Realtime`
\n
Specified by:
\n
`toText` in class `Number<Rational>`
\n
Returns:
the text representation of this number.
\n
• \n
\n\n\n\n
\n
• \n

#### equals

\n
`public boolean equals(Object that)`
\n
Compares this rational number against the specified object.
\n
\n
Specified by:
\n
`equals` in class `Number<Rational>`
\n
Parameters:
`that` - the object to compare with.
\n
Returns:
`true` if the objects are the same;\n `false` otherwise.
\n
• \n
\n\n\n\n
\n
• \n

#### hashCode

\n
`public int hashCode()`
\n
Returns the hash code for this rational number.
\n
\n
Specified by:
\n
`hashCode` in class `Number<Rational>`
\n
Returns:
the hash code value.
\n
• \n
\n\n\n\n
\n
• \n

#### longValue

\n
`public long longValue()`
\n
Returns the value of this rational number as a `long`.
\n
\n
Specified by:
\n
`longValue` in class `Number<Rational>`
\n
Returns:
the numeric value represented by this rational after conversion\n to type `long`.
\n
• \n
\n\n\n\n
\n
• \n

#### doubleValue

\n
`public double doubleValue()`
\n
Returns the value of this rational number as a `double`.
\n
\n
Specified by:
\n
`doubleValue` in class `Number<Rational>`
\n
Returns:
the numeric value represented by this rational after conversion\n to type `double`.
\n
• \n
\n\n\n\n
\n
• \n

#### compareTo

\n
`public int compareTo(Rational that)`
\n
Compares two rational number numerically.
\n
\n
Specified by:
\n
`compareTo` in interface `Comparable<Rational>`
\n
Specified by:
\n
`compareTo` in class `Number<Rational>`
\n
Parameters:
`that` - the rational number to compare with.
\n
Returns:
-1, 0 or 1 as this rational number is numerically less than, \n equal to, or greater than `that`.
\n
• \n
\n\n\n\n
\n
• \n

#### copy

\n
`public Rational copy()`
\n
Description copied from class: `Number`
\n
Returns a copy of this number \n `allocated` \n by the calling thread (possibly on the stack).
\n
\n
Specified by:
\n
`copy` in interface `javolution.lang.ValueType`
\n
Specified by:
\n
`copy` in class `Number<Rational>`
\n
Returns:
an identical and independant copy of this number.
\n
• \n
\n
• \n
\n
• \n
\n
\n
\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n