- All Superinterfaces:
Comparable<Number>
- All Known Subinterfaces:
IntegerNumber,RationalNumber
A number is some kind of representation of a real number.
Integer numbers and rational numbers live in two different universes, so are
never equal.
The natural comparison places some arbitrary order on Numbers consistent with
equals.
-
Method Summary
Modifier and TypeMethodDescriptionThe string representation used when this number appears inside of another expression.booleanIs this number infinite?booleanisOne()Is this number equal to 1?booleanisZero()Is this number equal to 0? Same as signum() == 0, but sometimes more convenient.intnumericalCompareTo(Number other) This is a numerical comparison, so the order is a numerical order based on the value of this and other.intsignum()Returns 0 if this number equals 0, -1 if this number is negative, 1 if this number is positive.Methods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
signum
int signum()Returns 0 if this number equals 0, -1 if this number is negative, 1 if this number is positive. -
isZero
boolean isZero()Is this number equal to 0? Same as signum() == 0, but sometimes more convenient. -
isOne
boolean isOne()Is this number equal to 1? -
isInfinite
boolean isInfinite()Is this number infinite?- Returns:
true, if it is positive/negative infinity;
false, if it is finite.
-
atomString
String atomString()The string representation used when this number appears inside of another expression. For example if the number is 3/4, this method could return (3/4), because in the expression 10*(3/4) you really need the parentheses. On the other hand, if the representation is 0.75, the parens probably are not necessary, and this method might return the same thing as the toString() method. -
numericalCompareTo
This is a numerical comparison, so the order is a numerical order based on the value of this and other.- Parameters:
other- a non-nullNumberwith the same type with this.- Returns:
- Returns a positive value if this is greater than other, 0 if this equals other, a negative value if this is less than other.
-