Class 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 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:
    Serialized Form
    • Constructor Detail

      • Rational

        public Rational()
        Zero
      • Rational

        public Rational​(int numerator,
                        int denominator)
        Create a rational number
        Parameters:
        denominator - number on top of fraction
        numerator - 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 class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(Rational num)
        Specified by:
        compareTo in interface java.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 class java.lang.Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class java.lang.Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class java.lang.Number