Interface RationalNumber

All Superinterfaces:
Comparable<RealNumber>, Number, RealNumber
All Known Subinterfaces:
AtLeast<N>, AtLeastEight, AtLeastEighteen, AtLeastEleven, AtLeastFifteen, AtLeastFive, AtLeastFour, AtLeastFourteen, AtLeastMinusOne, AtLeastNine, AtLeastNineteen, AtLeastOne, AtLeastSeven, AtLeastSeventeen, AtLeastSix, AtLeastSixteen, AtLeastTen, AtLeastThirteen, AtLeastThree, AtLeastTwelve, AtLeastTwenty, AtLeastTwo, AtLeastZero, AtMost<N>, AtMostEight, AtMostEighteen, AtMostEleven, AtMostFifteen, AtMostFive, AtMostFour, AtMostFourteen, AtMostMinusOne, AtMostNine, AtMostNineteen, AtMostOne, AtMostSeven, AtMostSeventeen, AtMostSix, AtMostSixteen, AtMostTen, AtMostThirteen, AtMostThree, AtMostTwelve, AtMostTwenty, AtMostTwo, AtMostZero, FourOrEight, Integer, NaturalNumber, NMinus1<N>, NPlus1<N>, PositiveInteger
All Known Implementing Classes:
ConcreteNumber, Eight, Eighteen, Eleven, Fifteen, Five, Four, Fourteen, MinusOne, Nine, Nineteen, One, Seven, Seventeen, Six, Sixteen, Ten, Thirteen, Three, Twelve, Twenty, Two, Zero

public sealed interface RationalNumber extends RealNumber permits Integer (not exhaustive)
A RationalNumber, also called a fraction, is a RealNumber that can be defined as a ratio of two Integers.
  • Method Details

    • numerator

      Integer numerator()
      Return the numerator
      Returns:
      the numerator
    • denominator

      Integer denominator()
      Return the denominator
      Returns:
      the denominator
    • intNumerator

      int intNumerator()
      Returns the numerator as a primitive int or throws an exception if its not in the range of primitive ints
      Returns:
      the numerator as an int
    • intDenominator

      int intDenominator()
      Returns the denominator as a primitive int or throws an exception if its not in the range of primitive ints
      Returns:
      the numerator as an int
    • longNumerator

      long longNumerator()
      Returns the numerator as a primitive long or throws an Exception if its not in the range of primitive longs
      Returns:
      the numerator as an long
    • longDenominator

      long longDenominator()
      Returns the denominator as a primitive long or throws an Exception if its not in the range of primitive longs
      Returns:
      the denominator as an long
    • isInt

      boolean isInt()
      Returns true if this RationalNumber's numerator and denomiator are both in the range of primitive ints
      Returns:
      true if this RationalNumber has int precision, false otherwise
    • isLong

      boolean isLong()
      Returns true if this RationalNumber's numerator and denomiator are both in the range of primitive longs
      Returns:
      true if this RationalNumber has long precision, false otherwise
    • plus

      default RationalNumber plus(RationalNumber n)
      Returns the sum of this RationalNumber and the given RationalNumber
      Parameters:
      n - the number to add to this one
      Returns:
      the sum of this number and the given number
    • minus

      default RationalNumber minus(RationalNumber n)
      Returns the difference between this RationalNumber and the given RationalNumber
      Parameters:
      n - the number to subtract from this one
      Returns:
      the difference of this number and the given number
    • times

      default RationalNumber times(RationalNumber n)
      Returns the product of multiplying this RationalNumber by the given RationalNumber
      Parameters:
      n - the factor to multiple by
      Returns:
      the product of real numbers
    • dividedBy

      default RationalNumber dividedBy(RationalNumber n)
      Returns the quotient of dividing this RationalNumber by the given RationalNumber
      Parameters:
      n - the number to divide this number by
      Returns:
      the quotient of dividing this number by the given number
    • reduce

      default RationalNumber reduce()
      Returns a RationalNumber that is equivalent to this RationalNumber reduced to its lowest terms
      Returns:
      a reduced RationalNumber
    • of

      static RationalNumber of(int numerator, int denominator)
      Creates a new RationalNumber from the given int numerator and denominator
      Parameters:
      numerator - the numerator
      denominator - the denominator
      Returns:
      a RationalNumber of numerator/denominator
      Throws:
      IllegalArgumentException - if denominator is 0
    • of

      static RationalNumber of(long numerator, long denominator)
      Creates a new RationalNumber from the given long numerator and denominator
      Parameters:
      numerator - the numerator
      denominator - the denominator
      Returns:
      a RationalNumber of numerator/denominator
      Throws:
      IllegalArgumentException - if denominator is 0
    • of

      static RationalNumber of(Integer numerator, Integer denominator)
      Creates a new RationalNumber from the given Integer numerator and denominator
      Parameters:
      numerator - the numerator
      denominator - the denominator
      Returns:
      a RationalNumber of numerator/denominator
      Throws:
      IllegalArgumentException - if denominator is ZERO