Class Rational
- java.lang.Object
-
- java.lang.Number
-
- com.singularsys.extensions.field.implementations.Rational
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Rational>
public class Rational extends java.lang.Number implements java.lang.Comparable<Rational>
A rational number represented as the quotient of two BigIntegers. An immutable type.Note if using Rational numbers with the
PrintVisitor
a special ruleRationalDivisionPrintRule
is needed to ensure divisions are correctly printed. This can be added withjep.getPrintVisitor().addSpecialRule(jep.getOperatorTable().getDivide(), new RationalDivisionPrintRule());
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Rational
add(Rational r)
int
compareTo(Rational num)
Rational
div(Rational r)
double
doubleValue()
boolean
equals(java.lang.Object obj)
float
floatValue()
java.math.BigInteger
getDenominator()
java.math.BigInteger
getNumerator()
int
hashCode()
int
intValue()
long
longValue()
Rational
mul(Rational r)
Rational
neg()
Rational
sub(Rational r)
java.lang.String
toString()
static Rational
valueOf(int a)
static Rational
valueOf(int a, int b)
static Rational
valueOf(long a)
-
-
-
Constructor Detail
-
Rational
public Rational()
Zero
-
Rational
public Rational(int numerator, int denominator)
Create a rational number- Parameters:
denominator
- number on top of fractionnumerator
- number on bottom of fraction
-
Rational
public Rational(int numerator)
-
Rational
public Rational(java.math.BigInteger num, java.math.BigInteger denom)
-
Rational
public Rational(long numerator)
-
Rational
public Rational(java.math.BigInteger val)
-
-
Method Detail
-
getNumerator
public java.math.BigInteger getNumerator()
-
getDenominator
public java.math.BigInteger getDenominator()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
neg
public Rational neg()
-
compareTo
public int compareTo(Rational num)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Rational>
-
valueOf
public static Rational valueOf(int a)
-
valueOf
public static Rational valueOf(long a)
-
valueOf
public static Rational valueOf(int a, int b)
-
intValue
public int intValue()
- Specified by:
intValue
in classjava.lang.Number
-
longValue
public long longValue()
- Specified by:
longValue
in classjava.lang.Number
-
floatValue
public float floatValue()
- Specified by:
floatValue
in classjava.lang.Number
-
doubleValue
public double doubleValue()
- Specified by:
doubleValue
in classjava.lang.Number
-
-