- All Superinterfaces:
Comparable<RealNumber>
,Number
- 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
,IrrationalNumber<N>
,NaturalNumber
,NMinus1<N>
,NPlus1<N>
,PositiveInteger
,RationalNumber
- All Known Implementing Classes:
ConcreteNumber
,Eight
,Eighteen
,Eleven
,Fifteen
,Five
,Four
,Fourteen
,MinusOne
,NegativeInfinity
,Nine
,Nineteen
,One
,PositiveInfinity
,Seven
,Seventeen
,Six
,Sixteen
,Ten
,Thirteen
,Three
,Twelve
,Twenty
,Two
,Zero
public sealed interface RealNumber
extends Number, Comparable<RealNumber>
permits RationalNumber, IrrationalNumber<N>, NegativeInfinity, PositiveInfinity (not exhaustive)
A
RealNumber
is an element of the set of
RealNumbers
ℝ-
Method Summary
Modifier and TypeMethodDescriptiondefault RealNumber
abs()
Returns thisRealNumber
's absolute valuedefault boolean
almostEquals
(double n) Returns true if the given double value is almost equal to thisRealNumber
's double value where almost equal means that their absolute difference is less thanFloatingPointMath#getMaxError()
static boolean
almostEquals
(double n1, double n2) Returns true if the given double precision values are almost equal as defined byFloatingPointMath#getMaxError()
default boolean
Returns true if the givenRealNumber
is almost equal to thisRealNumber
where almost equal means that their absolute difference is less than FloatingPointMath.getRealMaxError()Returns thisRealNumber
's value as aBigDecimal
default int
default RealNumber
Returns the quotient of dividing thisRealNumber
by the givenRealNumber
double
Returns thisRealNumber
's value with double-precision type.default boolean
Returns true if thisRealNumber
is greater than the givenRealNumber
, false otherwisedefault boolean
Returns true if thisRealNumber
is greater than or equal to the givenRealNumber
, false otherwiseboolean
isDouble()
Determines if thisRealNumber
's value has the precision of a primitive doubledefault boolean
Returns true if thisRealNumber
is less than the givenRealNumber
, false otherwisedefault boolean
Returns true if thisRealNumber
is less than or equal to the givenRealNumber
, false otherwisedefault RealNumber
minus
(RealNumber n) Returns the difference between thisRealNumber
and the givenRealNumber
default RealNumber
modulo
(RealNumber n) Returns the remainder of dividing thisRealNumber
by the givenRealNumber
static RealNumber
of
(double d) Creates a newRealNumber
for the given double precision valuestatic RealNumber
of
(BigDecimal number) Creates a newRealNumber
for the givenBigInteger
valuedefault RealNumber
plus
(RealNumber n) Returns the sum of thisRealNumber
and the givenRealNumber
default RealNumber
pow
(RealNumber exponent) Returns the product of exponentiating thisRealNumber
by the givenRealNumber
default RealNumber
times
(RealNumber n) Returns the product of multiplying thisRealNumber
by the givenRealNumber
default RealNumber
truncate()
Truncates thisRealNumber
towardZERO
-
Method Details
-
doubleValue
double doubleValue()Returns thisRealNumber
's value with double-precision type. Note that the value will be an approximation for irrational numbers such as Pi, Phi, e or repeating decimals such as 0.666..., 1.851851851..., etc.- Returns:
- the double value that is the closest approximation to this real number
-
bigDecimalValue
BigDecimal bigDecimalValue()Returns thisRealNumber
's value as aBigDecimal
- Returns:
- the
BigDecimal
value
-
isDouble
boolean isDouble()Determines if thisRealNumber
's value has the precision of a primitive double- Returns:
- true if this
RealNumber
is double precision, false, if BigDecimal precision
-
plus
Returns the sum of thisRealNumber
and the givenRealNumber
- Parameters:
n
- the number to add to this one- Returns:
- the sum of this number and the given number
-
minus
Returns the difference between thisRealNumber
and the givenRealNumber
- 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 thisRealNumber
by the givenRealNumber
- Parameters:
n
- the factor to multiple by- Returns:
- the product of real numbers
-
dividedBy
Returns the quotient of dividing thisRealNumber
by the givenRealNumber
- Parameters:
n
- the number to divide this number by- Returns:
- the quotient of dividing this number by the given number
-
modulo
Returns the remainder of dividing thisRealNumber
by the givenRealNumber
- Parameters:
n
- the number to modulo by- Returns:
- the remainder of this number divided by the given number
-
abs
Returns thisRealNumber
's absolute value- Returns:
- this number's absolute value
-
pow
Returns the product of exponentiating thisRealNumber
by the givenRealNumber
- Parameters:
exponent
- the exponent- Returns:
- the exponential product of this number by the given exponent
-
truncate
Truncates thisRealNumber
towardZERO
- Returns:
- a real number rounded toward 0
-
lessThan
Returns true if thisRealNumber
is less than the givenRealNumber
, false otherwise- Parameters:
n
- the real number to test- Returns:
- the truth of this number being less than the given number
-
lessThanOrEqualTo
Returns true if thisRealNumber
is less than or equal to the givenRealNumber
, false otherwise- Parameters:
n
- the real number to test- Returns:
- the truth of this number being less than or equal to the given number
-
greaterThan
Returns true if thisRealNumber
is greater than the givenRealNumber
, false otherwise- Parameters:
n
- the real number to test- Returns:
- the truth of this number being greater than the given number
-
greaterThanOrEqualTo
Returns true if thisRealNumber
is greater than or equal to the givenRealNumber
, false otherwise- Parameters:
n
- the real number to test- Returns:
- the truth of this number being greater than or equal to the given number
-
almostEquals
Returns true if the givenRealNumber
is almost equal to thisRealNumber
where almost equal means that their absolute difference is less than FloatingPointMath.getRealMaxError()- Parameters:
n
- the number to compare- Returns:
- true if the number is nearly equal to this one, false otherwise
-
almostEquals
default boolean almostEquals(double n) Returns true if the given double value is almost equal to thisRealNumber
's double value where almost equal means that their absolute difference is less thanFloatingPointMath#getMaxError()
- Parameters:
n
- the number to compare- Returns:
- true if the number is nearly equal to this one, false otherwise
-
almostEquals
static boolean almostEquals(double n1, double n2) Returns true if the given double precision values are almost equal as defined byFloatingPointMath#getMaxError()
- Parameters:
n1
- the first numbern2
- the second number- Returns:
- true if the numbers are almost equal, false otherwise
-
compareTo
- Specified by:
compareTo
in interfaceComparable<RealNumber>
-
of
Creates a newRealNumber
for the given double precision value- Parameters:
d
- the double value- Returns:
- a
RealNumber
for the value d
-
of
Creates a newRealNumber
for the givenBigInteger
value- Parameters:
number
- the double value- Returns:
- a
RealNumber
for the number
-