Class BigRational

    • Constructor Detail

      • BigRational

        public BigRational​(BigInteger n)
        Constructor for an integer.
        Parameters:
        n - Number in decimal representation.
      • BigRational

        public BigRational​(BigInteger num,
                           BigInteger den)
        Constructor for a rational number.
        Parameters:
        num - Numerator
        den - Denominator
    • Method Detail

      • add

        public BigRational add​(BigRational b)
        Computes the sum of this and the argument.
        Parameters:
        b - Argument.
        Returns:
        sum
      • subtract

        public BigRational subtract​(BigRational b)
        Computes the subtraction of this and the argument.
        Parameters:
        b - Argument.
        Returns:
        subtraction
      • multiply

        public BigRational multiply​(BigInteger b)
        Computes the product of this and the argument.
        Parameters:
        b - Argument.
        Returns:
        product
      • multiply

        public BigRational multiply​(BigRational b)
        Computes the product of this and the argument.
        Parameters:
        b - Argument.
        Returns:
        product
      • divide

        public BigRational divide​(BigInteger b)
        Computes the fraction of this and the argument.
        Parameters:
        b - Argument.
        Returns:
        fraction
      • divide

        public BigRational divide​(BigRational b)
        Computes the fraction of this and the argument.
        Parameters:
        b - Argument.
        Returns:
        fraction
      • abs

        public BigRational abs()
        Returns:
        absolut value
      • negate

        public BigRational negate()
        Returns:
        copy of this with opposite sign
      • reciprocal

        public BigRational reciprocal()
        Returns:
        1/this
      • normalize

        public BigRational normalize()
        Returns:
        this with gcd of numerator and denominator reduced to 1.
      • getNumerator

        public BigInteger getNumerator()
        Returns:
        The numerator of this number.
      • getDenominator

        public BigInteger getDenominator()
        Returns:
        The denominator of this number.
      • signum

        public int signum()
        Returns:
        <0/0/>0 if this is negative/zero/positive.
      • floorInt

        public BigInteger floorInt()
        Returns:
        the nearest smaller-or-equal integer value.
      • ceilInt

        public BigInteger ceilInt()
        Returns:
        the nearest bigger-or-equal integer value.
      • compareTo

        public int compareTo​(BigInteger other)
      • equals

        public boolean equals​(BigInteger other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • byteValue

        public byte byteValue()
        Overrides:
        byteValue in class Number
        Returns:
        this as a byte (rounding may be necessary)
      • intValue

        public int intValue()
        Specified by:
        intValue in class Number
        Returns:
        this as an int (rounding may be necessary)
      • longValue

        public long longValue()
        Specified by:
        longValue in class Number
        Returns:
        this as a long integer (rounding may be necessary)
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class Number
        Returns:
        this as a float (rounding may be necessary)
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class Number
        Returns:
        this as a double (rounding may be necessary)
      • toBigDecimal

        public BigDecimal toBigDecimal​(Scale decPrec)
        Converts this to a BigDecimal with decPrec digits precision. Because we can access numerator and denominator directly, implementation in this class is more efficient than as BigFloat.valueOf(BigRational).
        Parameters:
        decPrec - Precision in decimal digits.
        Returns:
        this as a big float with the wanted precision.
      • toString

        public String toString()
        Overrides:
        toString in class Object
        Returns:
        this as a (fractional) string
      • toString

        public String toString​(Scale decPrec)
        Converts this into a string with the given decimal digits precision.
        Parameters:
        decPrec - output precision in decimal digits.
        Returns:
        this as a string with the wanted precision.