- 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 Integer
s.-
Method Summary
Modifier and TypeMethodDescriptionReturn the denominatordefault RationalNumber
Returns the quotient of dividing thisRationalNumber
by the givenRationalNumber
int
Returns the denominator as a primitive int or throws an exception if its not in the range of primitive intsint
Returns the numerator as a primitive int or throws an exception if its not in the range of primitive intsboolean
isInt()
Returns true if this RationalNumber's numerator and denomiator are both in the range of primitive intsboolean
isLong()
Returns true if this RationalNumber's numerator and denomiator are both in the range of primitive longslong
Returns the denominator as a primitive long or throws an Exception if its not in the range of primitive longslong
Returns the numerator as a primitive long or throws an Exception if its not in the range of primitive longsdefault RationalNumber
Returns the difference between thisRationalNumber
and the givenRationalNumber
Return the numeratorstatic RationalNumber
of
(int numerator, int denominator) Creates a newRationalNumber
from the given int numerator and denominatorstatic RationalNumber
of
(long numerator, long denominator) Creates a newRationalNumber
from the given long numerator and denominatorstatic RationalNumber
Creates a newRationalNumber
from the given Integer numerator and denominatordefault RationalNumber
Returns the sum of thisRationalNumber
and the givenRationalNumber
default RationalNumber
reduce()
Returns aRationalNumber
that is equivalent to thisRationalNumber
reduced to its lowest termsdefault RationalNumber
Returns the product of multiplying thisRationalNumber
by the givenRationalNumber
Methods 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
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
Returns the sum of thisRationalNumber
and 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 thisRationalNumber
and 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 thisRationalNumber
by the givenRationalNumber
- Parameters:
n
- the factor to multiple by- Returns:
- the product of real numbers
-
dividedBy
Returns the quotient of dividing thisRationalNumber
by the givenRationalNumber
- Parameters:
n
- the number to divide this number by- Returns:
- the quotient of dividing this number by the given number
-
reduce
Returns aRationalNumber
that is equivalent to thisRationalNumber
reduced to its lowest terms- Returns:
- a reduced
RationalNumber
-
of
Creates a newRationalNumber
from the given int numerator and denominator- Parameters:
numerator
- the numeratordenominator
- the denominator- Returns:
- a
RationalNumber
of numerator/denominator - Throws:
IllegalArgumentException
- if denominator is 0
-
of
Creates a newRationalNumber
from the given long numerator and denominator- Parameters:
numerator
- the numeratordenominator
- the denominator- Returns:
- a
RationalNumber
of numerator/denominator - Throws:
IllegalArgumentException
- if denominator is 0
-
of
Creates a newRationalNumber
from the given Integer numerator and denominator- Parameters:
numerator
- the numeratordenominator
- the denominator- Returns:
- a
RationalNumber
of numerator/denominator - Throws:
IllegalArgumentException
- if denominator isZERO
-