Package cc.redberry.rings
Class Rational<E>
- java.lang.Object
-
- cc.redberry.rings.Rational<E>
-
- All Implemented Interfaces:
Stringifiable<Rational<E>>
,Serializable
,Comparable<Rational<E>>
public class Rational<E> extends Object implements Comparable<Rational<E>>, Stringifiable<Rational<E>>, Serializable
- See Also:
- Serialized Form
-
-
Method Summary
Modifier and Type Method Description Rational<E>
abs()
Returns the absolute value of thisRational
.Rational<E>
add(Rational<E> that)
Add that to thisRational<E>
add(E that)
Add that to thisint
compareTo(Rational<E> object)
E
denominator()
Denominator of this rationalRational<E>
divide(Rational<E> oth)
Divide this by othRational<E>
divide(E oth)
Divide this by othboolean
equals(Object o)
FactorDecomposition<E>
factorDenominator()
Factor decomposition of denominatorFactorDecomposition<E>
factorNumerator()
Factor decomposition of denominatorint
hashCode()
boolean
isIntegral()
whether this rational is integralboolean
isOne()
whether this rational is oneboolean
isZero()
whether this rational is zero<O> Rational<O>
map(Ring<O> ring, Function<E,O> function)
Maps rational to a new ringRational<E>
map(Function<E,E> function)
Maps rationalRational<E>
multiply(Rational<E> oth)
Multiply this by othRational<E>
multiply(E oth)
Multiply this by othRational<E>
negate()
Negate this fractionRational<E>[]
normal()
Reduces this rational to normal form by doing division with remainder, that is ifnumerator = div * denominator + rem
then the array(div, rem/denominator)
will be returned.E
numerator()
Numerator of this rationalE
numeratorExact()
Numerator of this rationalstatic <E> Rational<E>
one(Ring<E> ring)
Constructs oneRational<E>
pow(int exponent)
Raise this in a powerexponent
Rational<E>
pow(long exponent)
Raise this in a powerexponent
Rational<E>
pow(BigInteger exponent)
Raise this in a powerexponent
Rational<E>
reciprocal()
Reciprocal of thisint
signum()
Signum of this rationalStream<E>
stream()
Stream of numerator and denominatorRational<E>
subtract(Rational<E> that)
Add that to thisRational<E>
subtract(E that)
Subtract that from thisString
toString()
String
toString(IStringifier<Rational<E>> stringifier)
convert this to string with the use of stringifierString
toStringFactors(IStringifier<Rational<E>> stringifier)
static <E> Rational<E>
zero(Ring<E> ring)
Constructs zero
-
-
-
Method Detail
-
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 ifnumerator = 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
-
abs
public Rational<E> abs()
Returns the absolute value of thisRational
.- Returns:
- the absolute value as a
Rational
.
-
compareTo
public int compareTo(Rational<E> object)
- Specified by:
compareTo
in interfaceComparable<E>
-
pow
public Rational<E> pow(int exponent)
Raise this in a powerexponent
- Parameters:
exponent
- exponent
-
pow
public Rational<E> pow(long exponent)
Raise this in a powerexponent
- Parameters:
exponent
- exponent
-
pow
public Rational<E> pow(BigInteger exponent)
Raise this in a powerexponent
- Parameters:
exponent
- exponent
-
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 interfaceStringifiable<E>
-
toStringFactors
public String toStringFactors(IStringifier<Rational<E>> stringifier)
-
-