- 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
A
RationalNumber, also called a fraction, is
a RealNumber that can be defined as a ratio
of two Integers.-
Method Summary
Modifier and TypeMethodDescriptionReturn the denominatordefault RationalNumberReturns the quotient of dividing thisRationalNumberby the givenRationalNumberintReturns the denominator as a primitive int or throws an exception if its not in the range of primitive intsintReturns the numerator as a primitive int or throws an exception if its not in the range of primitive intsbooleanisInt()Returns true if this RationalNumber's numerator and denomiator are both in the range of primitive intsbooleanisLong()Returns true if this RationalNumber's numerator and denomiator are both in the range of primitive longslongReturns the denominator as a primitive long or throws an Exception if its not in the range of primitive longslongReturns the numerator as a primitive long or throws an Exception if its not in the range of primitive longsdefault RationalNumberReturns the difference between thisRationalNumberand the givenRationalNumberReturn the numeratorstatic RationalNumberof(int numerator, int denominator) Creates a newRationalNumberfrom the given int numerator and denominatorstatic RationalNumberof(long numerator, long denominator) Creates a newRationalNumberfrom the given long numerator and denominatorstatic RationalNumberCreates a newRationalNumberfrom the given Integer numerator and denominatordefault RationalNumberReturns the sum of thisRationalNumberand the givenRationalNumberdefault RationalNumberreduce()Returns aRationalNumberthat is equivalent to thisRationalNumberreduced to its lowest termsdefault RationalNumberReturns the product of multiplying thisRationalNumberby the givenRationalNumberMethods inherited from interface org.zfcj.math.numbers.RealNumber
abs, almostEquals, almostEquals, bigDecimalValue, compareTo, dividedBy, doubleValue, greaterThan, greaterThanOrEqualTo, isDouble, lessThan, lessThanOrEqualTo, minus, modulo, plus, pow, times, truncate
-
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
RationalNumberhas 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
RationalNumberhas long precision, false otherwise
-
plus
Returns the sum of thisRationalNumberand the givenRationalNumber- Parameters:
n- the number to add to this one- Returns:
- the sum of this number and the given number
-
minus
Returns the difference between thisRationalNumberand the givenRationalNumber- Parameters:
n- the number to subtract from this one- Returns:
- the difference of this number and the given number
-
times
Returns the product of multiplying thisRationalNumberby the givenRationalNumber- Parameters:
n- the factor to multiple by- Returns:
- the product of real numbers
-
dividedBy
Returns the quotient of dividing thisRationalNumberby the givenRationalNumber- Parameters:
n- the number to divide this number by- Returns:
- the quotient of dividing this number by the given number
-
reduce
Returns aRationalNumberthat is equivalent to thisRationalNumberreduced to its lowest terms- Returns:
- a reduced
RationalNumber
-
of
Creates a newRationalNumberfrom the given int numerator and denominator- Parameters:
numerator- the numeratordenominator- the denominator- Returns:
- a
RationalNumberof numerator/denominator - Throws:
IllegalArgumentException- if denominator is 0
-
of
Creates a newRationalNumberfrom the given long numerator and denominator- Parameters:
numerator- the numeratordenominator- the denominator- Returns:
- a
RationalNumberof numerator/denominator - Throws:
IllegalArgumentException- if denominator is 0
-
of
Creates a newRationalNumberfrom the given Integer numerator and denominator- Parameters:
numerator- the numeratordenominator- the denominator- Returns:
- a
RationalNumberof numerator/denominator - Throws:
IllegalArgumentException- if denominator isZERO
-