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
PrintVisitora special ruleRationalDivisionPrintRuleis 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 Rationaladd(Rational r)intcompareTo(Rational num)Rationaldiv(Rational r)doubledoubleValue()booleanequals(java.lang.Object obj)floatfloatValue()java.math.BigIntegergetDenominator()java.math.BigIntegergetNumerator()inthashCode()intintValue()longlongValue()Rationalmul(Rational r)Rationalneg()Rationalsub(Rational r)java.lang.StringtoString()static RationalvalueOf(int a)static RationalvalueOf(int a, int b)static RationalvalueOf(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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
neg
public Rational neg()
-
compareTo
public int compareTo(Rational num)
- Specified by:
compareToin 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:
intValuein classjava.lang.Number
-
longValue
public long longValue()
- Specified by:
longValuein classjava.lang.Number
-
floatValue
public float floatValue()
- Specified by:
floatValuein classjava.lang.Number
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classjava.lang.Number
-
-