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
-
Field Summary
-
Constructor Summary
-
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
-
Field Details
-
ring
The ring.
-
-
Constructor Details
-
Rational
-
Rational
-
-
Method Details
-
zero
Constructs zero -
one
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
Numerator of this rational -
numeratorExact
Numerator of this rational -
denominator
Denominator of this rational -
factorDenominator
Factor decomposition of denominator -
factorNumerator
Factor decomposition of denominator -
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
Returns the absolute value of thisRational
.- Returns:
- the absolute value as a
Rational
.
-
reciprocal
Reciprocal of this -
multiply
Multiply this by oth -
divide
Divide this by oth -
multiply
Multiply this by oth -
divide
Divide this by oth -
negate
Negate this fraction -
add
Add that to this -
subtract
Add that to this -
add
Add that to this -
subtract
Subtract that from this -
compareTo
- Specified by:
compareTo
in interfaceComparable<E>
-
pow
Raise this in a powerexponent
- Parameters:
exponent
- exponent
-
pow
Raise this in a powerexponent
- Parameters:
exponent
- exponent
-
pow
Raise this in a powerexponent
- Parameters:
exponent
- exponent
-
map
Maps rational to a new ring -
map
Maps rational -
stream
Stream of numerator and denominator -
equals
-
hashCode
public int hashCode() -
toString
Description copied from interface:Stringifiable
convert this to string with the use of stringifier- Specified by:
toString
in interfaceStringifiable<E>
-
toStringFactors
-
toString
-