- 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 RealNumberabs()Returns thisRealNumber's absolute valuedefault booleanalmostEquals(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 booleanalmostEquals(double n1, double n2) Returns true if the given double precision values are almost equal as defined byFloatingPointMath#getMaxError()default booleanReturns true if the givenRealNumberis almost equal to thisRealNumberwhere almost equal means that their absolute difference is less than FloatingPointMath.getRealMaxError()Returns thisRealNumber's value as aBigDecimaldefault intdefault RealNumberReturns the quotient of dividing thisRealNumberby the givenRealNumberdoubleReturns thisRealNumber's value with double-precision type.default booleanReturns true if thisRealNumberis greater than the givenRealNumber, false otherwisedefault booleanReturns true if thisRealNumberis greater than or equal to the givenRealNumber, false otherwisebooleanisDouble()Determines if thisRealNumber's value has the precision of a primitive doubledefault booleanReturns true if thisRealNumberis less than the givenRealNumber, false otherwisedefault booleanReturns true if thisRealNumberis less than or equal to the givenRealNumber, false otherwisedefault RealNumberminus(RealNumber n) Returns the difference between thisRealNumberand the givenRealNumberdefault RealNumbermodulo(RealNumber n) Returns the remainder of dividing thisRealNumberby the givenRealNumberstatic RealNumberof(double d) Creates a newRealNumberfor the given double precision valuestatic RealNumberof(BigDecimal number) Creates a newRealNumberfor the givenBigIntegervaluedefault RealNumberplus(RealNumber n) Returns the sum of thisRealNumberand the givenRealNumberdefault RealNumberpow(RealNumber exponent) Returns the product of exponentiating thisRealNumberby the givenRealNumberdefault RealNumbertimes(RealNumber n) Returns the product of multiplying thisRealNumberby the givenRealNumberdefault RealNumbertruncate()Truncates thisRealNumbertowardZERO
-
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
BigDecimalvalue
-
isDouble
boolean isDouble()Determines if thisRealNumber's value has the precision of a primitive double- Returns:
- true if this
RealNumberis double precision, false, if BigDecimal precision
-
plus
Returns the sum of thisRealNumberand 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 thisRealNumberand 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 thisRealNumberby the givenRealNumber- Parameters:
n- the factor to multiple by- Returns:
- the product of real numbers
-
dividedBy
Returns the quotient of dividing thisRealNumberby 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 thisRealNumberby 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 thisRealNumberby the givenRealNumber- Parameters:
exponent- the exponent- Returns:
- the exponential product of this number by the given exponent
-
truncate
Truncates thisRealNumbertowardZERO- Returns:
- a real number rounded toward 0
-
lessThan
Returns true if thisRealNumberis 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 thisRealNumberis 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 thisRealNumberis 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 thisRealNumberis 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 givenRealNumberis almost equal to thisRealNumberwhere 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:
compareToin interfaceComparable<RealNumber>
-
of
Creates a newRealNumberfor the given double precision value- Parameters:
d- the double value- Returns:
- a
RealNumberfor the value d
-
of
Creates a newRealNumberfor the givenBigIntegervalue- Parameters:
number- the double value- Returns:
- a
RealNumberfor the number
-