Class Rational
java.lang.Object
java.lang.Number
com.singularsys.extensions.field.implementations.Rational
- All Implemented Interfaces:
Serializable,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 rule RationalDivisionPrintRule is needed to
ensure divisions are correctly printed. This can be added with
jep.getPrintVisitor().addSpecialRule(jep.getOperatorTable().getDivide(),
new RationalDivisionPrintRule());
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRational()ZeroRational(int numerator) Rational(int numerator, int denominator) Create a rational numberRational(long numerator) Rational(long numerator2, long denominator2) Constructor with two longs.Rational(BigInteger val) Rational(BigInteger num, BigInteger denom) -
Method Summary
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
ZERO
-
ONE
-
TWO
-
MINUSONE
-
HALF
-
-
Constructor Details
-
Rational
public Rational()Zero -
Rational
public Rational(int numerator, int denominator) Create a rational number- Parameters:
numerator- number on bottom of fractiondenominator- number on top of fraction
-
Rational
public Rational(int numerator) -
Rational
-
Rational
public Rational(long numerator) -
Rational
-
Rational
public Rational(long numerator2, long denominator2) Constructor with two longs.- Parameters:
numerator2-denominator2-- Since:
- Jep 4.1 extensions 2.2
-
-
Method Details
-
getNumerator
-
getDenominator
-
equals
-
hashCode
public int hashCode() -
toString
-
add
-
sub
-
mul
-
div
-
neg
-
compareTo
- Specified by:
compareToin interfaceComparable<Rational>
-
valueOf
-
valueOf
-
valueOf
-
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber
-