cc.redberry.rings

## Class Rational<E>

• ### Field Summary

Fields
Modifier and Type Field and Description
`Ring<E>` `ring`
The ring.
• ### Constructor Summary

Constructors
Constructor and Description
```Rational(Ring<E> ring, E numerator)```
```Rational(Ring<E> ring, E numerator, E denominator)```
• ### Method Summary

All Methods
Modifier and Type Method and Description
`Rational<E>` `abs()`
Returns the absolute value of this `Rational`.
`Rational<E>` `add(E that)`
`Rational<E>` `add(Rational<E> that)`
`int` `compareTo(Rational<E> object)`
`E` `denominator()`
Denominator of this rational
`Rational<E>` `divide(E oth)`
Divide this by oth
`Rational<E>` `divide(Rational<E> oth)`
Divide this by oth
`boolean` `equals(Object o)`
`FactorDecomposition<E>` `factorDenominator()`
Factor decomposition of denominator
`FactorDecomposition<E>` `factorNumerator()`
Factor decomposition of denominator
`int` `hashCode()`
`boolean` `isIntegral()`
whether this rational is integral
`boolean` `isOne()`
whether this rational is one
`boolean` `isZero()`
whether this rational is zero
`Rational<E>` `map(Function<E,E> function)`
Maps rational
`<O> Rational<O>` ```map(Ring<O> ring, Function<E,O> function)```
Maps rational to a new ring
`Rational<E>` `multiply(E oth)`
Multiply this by oth
`Rational<E>` `multiply(Rational<E> oth)`
Multiply this by oth
`Rational<E>` `negate()`
Negate this fraction
`Rational<E>[]` `normal()`
Reduces this rational to normal form by doing division with remainder, that is if ```numerator = div * denominator + rem``` then the array `(div, rem/denominator)` will be returned.
`E` `numerator()`
Numerator of this rational
`E` `numeratorExact()`
Numerator of this rational
`static <E> Rational<E>` `one(Ring<E> ring)`
Constructs one
`Rational<E>` `pow(BigInteger exponent)`
Raise this in a power `exponent`
`Rational<E>` `pow(int exponent)`
Raise this in a power `exponent`
`Rational<E>` `pow(long exponent)`
Raise this in a power `exponent`
`Rational<E>` `reciprocal()`
Reciprocal of this
`int` `signum()`
Signum of this rational
`Stream<E>` `stream()`
Stream of numerator and denominator
`Rational<E>` `subtract(E that)`
Subtract that from this
`Rational<E>` `subtract(Rational<E> that)`
`String` `toString()`
`String` `toString(IStringifier<Rational<E>> stringifier)`
convert this to string with the use of stringifier
`String` `toStringFactors(IStringifier<Rational<E>> stringifier)`
`static <E> Rational<E>` `zero(Ring<E> ring)`
Constructs zero
• ### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### ring

`public final Ring<E> ring`
The ring.
• ### Constructor Detail

• #### Rational

```public Rational(Ring<E> ring,
E numerator)```
• #### Rational

```public Rational(Ring<E> ring,
E numerator,
E denominator)```
• ### Method Detail

• #### zero

`public static <E> Rational<E> zero(Ring<E> ring)`
Constructs zero
• #### one

`public static <E> Rational<E> one(Ring<E> ring)`
Constructs one
• #### isZero

`public boolean isZero()`
whether this rational is zero
• #### isOne

`public boolean isOne()`
whether this rational is one
• #### isIntegral

`public boolean isIntegral()`
whether this rational is integral
• #### numerator

`public E numerator()`
Numerator of this rational
• #### numeratorExact

`public E numeratorExact()`
Numerator of this rational
• #### denominator

`public E denominator()`
Denominator of this rational
• #### factorDenominator

`public FactorDecomposition<E> factorDenominator()`
Factor decomposition of denominator
• #### factorNumerator

`public FactorDecomposition<E> factorNumerator()`
Factor decomposition of denominator
• #### normal

`public Rational<E>[] normal()`
Reduces this rational to normal form by doing division with remainder, that is if ```numerator = div * denominator + rem``` then the array `(div, rem/denominator)` will be returned. If either div or rem is zero an singleton array with this instance will be returned.
• #### signum

`public int signum()`
Signum of this rational
• #### reciprocal

`public Rational<E> reciprocal()`
Reciprocal of this
• #### multiply

`public Rational<E> multiply(Rational<E> oth)`
Multiply this by oth
• #### divide

`public Rational<E> divide(Rational<E> oth)`
Divide this by oth
• #### multiply

`public Rational<E> multiply(E oth)`
Multiply this by oth
• #### divide

`public Rational<E> divide(E oth)`
Divide this by oth
• #### negate

`public Rational<E> negate()`
Negate this fraction

`public Rational<E> add(Rational<E> that)`
• #### subtract

`public Rational<E> subtract(Rational<E> that)`

`public Rational<E> add(E that)`
• #### subtract

`public Rational<E> subtract(E that)`
Subtract that from this
• #### compareTo

`public int compareTo(Rational<E> object)`
Specified by:
`compareTo` in interface `Comparable<Rational<E>>`
• #### pow

`public Rational<E> pow(int exponent)`
Raise this in a power `exponent`
Parameters:
`exponent` - exponent
• #### pow

`public Rational<E> pow(long exponent)`
Raise this in a power `exponent`
Parameters:
`exponent` - exponent
• #### pow

`public Rational<E> pow(BigInteger exponent)`
Raise this in a power `exponent`
Parameters:
`exponent` - exponent
• #### map

```public <O> Rational<O> map(Ring<O> ring,
Function<E,O> function)```
Maps rational to a new ring
• #### map

`public Rational<E> map(Function<E,E> function)`
Maps rational
• #### stream

`public Stream<E> stream()`
Stream of numerator and denominator
• #### equals

`public boolean equals(Object o)`
Overrides:
`equals` in class `Object`
• #### hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### toString

`public String toString(IStringifier<Rational<E>> stringifier)`
Description copied from interface: `Stringifiable`
convert this to string with the use of stringifier
Specified by:
`toString` in interface `Stringifiable<Rational<E>>`
• #### toStringFactors

`public String toStringFactors(IStringifier<Rational<E>> stringifier)`
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`