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
All Methods Static Methods Instance Methods Concrete Methods 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 thisintcompareTo(Rational<E> object)Edenominator()Denominator of this rationalRational<E>divide(Rational<E> oth)Divide this by othRational<E>divide(E oth)Divide this by othbooleanequals(Object o)FactorDecomposition<E>factorDenominator()Factor decomposition of denominatorFactorDecomposition<E>factorNumerator()Factor decomposition of denominatorinthashCode()booleanisIntegral()whether this rational is integralbooleanisOne()whether this rational is onebooleanisZero()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 + remthen the array(div, rem/denominator)will be returned.Enumerator()Numerator of this rationalEnumeratorExact()Numerator of this rationalstatic <E> Rational<E>one(Ring<E> ring)Constructs oneRational<E>pow(int exponent)Raise this in a powerexponentRational<E>pow(long exponent)Raise this in a powerexponentRational<E>pow(BigInteger exponent)Raise this in a powerexponentRational<E>reciprocal()Reciprocal of thisintsignum()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 thisStringtoString()StringtoString(IStringifier<Rational<E>> stringifier)convert this to string with the use of stringifierStringtoStringFactors(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 + remthen 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:
compareToin 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:Stringifiableconvert this to string with the use of stringifier- Specified by:
toStringin interfaceStringifiable<E>
-
toStringFactors
public String toStringFactors(IStringifier<Rational<E>> stringifier)
-
-