Class nl.coffee.math.AbstractRealNumber
java.lang.Object
|
+--java.lang.Number
|
+--nl.coffee.math.AbstractRealNumber
- Subclasses:
- AbstractCompositeNumber, AbstractRationalNumber
- public abstract class AbstractRealNumber
- extends java.lang.Number
- implements RealNumber
Abstract base class for RealNumber
implementations.
Concrete subclasses should provide implementations for the following
methods:
getSign()
--
Determines the sign of this number
toBigDecimal(int,int)
--
Converts the value of this
number to a BigDecimal
with the specified precision,
using the specified rounding mode
trunc()
--
Truncates the value of this number to
an IntegerNumber
- Since:
- JUMP_1.0
- Version:
- 1.2 199809.24
- Author:
- Ernst de Haan
- See Also:
- Serialized Form
Methods inherited from class java.lang.Number |
byteValue, doubleValue, floatValue, intValue, longValue, shortValue |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait |
AbstractRealNumber
protected AbstractRealNumber()
- Constructs a new
AbstractRealNumber
object.
hashCode
public int hashCode()
- Overrides:
- hashCode in class java.lang.Object
equals
public final boolean equals(java.lang.Object o)
- Overrides:
- equals in class java.lang.Object
compareTo
public final int compareTo(RealNumber n)
throws java.lang.IllegalArgumentException,
CanNotCompareException
- Description copied from interface:
Returns -1, 0 or 1 as this number is less than, equal to, or greater
than n, where n is a real number. If this number
cannot be compared with n, then
n.retryCompare(this)
should be called in order to try
to let n compare to this. If that succeeds, the negative of
the result may be returned. If fails, it will throw a
CanNotCompareException
.
- Specified by:
- compareTo in interface RealNumber
retryCompare
public int retryCompare(RealNumber n)
throws java.lang.IllegalArgumentException,
CanNotCompareException
- Description copied from interface:
Returns -1, 0 or 1 as this number is less than, equal to, or greater
than n, where n is a real number. If this number
cannot be compared with n, then a
CanNotCompareException
is thrown.
- Specified by:
- retryCompare in interface RealNumber
abs
public RealNumber abs()
- Description copied from interface:
Computes |this|. The returned value is allways >= 0.
- Specified by:
- abs in interface RealNumber
negate
public RealNumber negate()
- Description copied from interface:
Computes -this.
- Specified by:
- negate in interface RealNumber
invert
public RealNumber invert()
- Description copied from interface:
Computes 1/this.
- Specified by:
- invert in interface RealNumber
add
public RealNumber add(RealNumber n)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Computes this+n, where n is a real number.
- Specified by:
- add in interface RealNumber
subtract
public RealNumber subtract(RealNumber n)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Computes this-n, where n is a real number.
- Specified by:
- subtract in interface RealNumber
multiply
public RealNumber multiply(RealNumber n)
- Description copied from interface:
Computes this*n, where n is a real number.
- Specified by:
- multiply in interface RealNumber
divide
public RealNumber divide(RealNumber n)
throws java.lang.IllegalArgumentException,
java.lang.ArithmeticException
- Description copied from interface:
Computes this/n, where n is a real number.
- Specified by:
- divide in interface RealNumber
pow
public RealNumber pow(RealNumber n)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Computes this**n, where n is a real number.
- Specified by:
- pow in interface RealNumber
fitsLong
public boolean fitsLong()
- Description copied from interface:
Determines if the truncated value of this number fits in a
long
.
- Specified by:
- fitsLong in interface RealNumber
fitsInt
public boolean fitsInt()
- Description copied from interface:
Determines if the truncated value of this number fits in an
int
.
- Specified by:
- fitsInt in interface RealNumber
fitsShort
public boolean fitsShort()
- Description copied from interface:
Determines if the truncated value of this number fits in a
short
.
- Specified by:
- fitsShort in interface RealNumber
fitsByte
public boolean fitsByte()
- Description copied from interface:
Determines if the truncated value of this number fits in a
byte
.
- Specified by:
- fitsByte in interface RealNumber
fitsDouble
public boolean fitsDouble()
- Description copied from interface:
Determines if the rounded value of this number fits in a
double
.
- Specified by:
- fitsDouble in interface RealNumber
fitsFloat
public boolean fitsFloat()
- Description copied from interface:
Determines if the rounded value of this number fits in a
float
.
- Specified by:
- fitsFloat in interface RealNumber
longValue
public long longValue()
- Description copied from interface:
Returns the value of this number as a long
. This may
involve rounding.
- Specified by:
- longValue in interface RealNumber
- Overrides:
- longValue in class java.lang.Number
intValue
public int intValue()
- Description copied from interface:
Returns the value of this number as an int
. This may
involve rounding.
- Specified by:
- intValue in interface RealNumber
- Overrides:
- intValue in class java.lang.Number
shortValue
public short shortValue()
- Description copied from interface:
Returns the value of this number as a short
. This may
involve rounding.
- Specified by:
- shortValue in interface RealNumber
- Overrides:
- shortValue in class java.lang.Number
byteValue
public byte byteValue()
- Description copied from interface:
Returns the value of this number as a byte
. This may
involve rounding.
- Specified by:
- byteValue in interface RealNumber
- Overrides:
- byteValue in class java.lang.Number
doubleValue
public double doubleValue()
- Description copied from interface:
Returns the value of this number as a double
. This may
involve rounding.
- Specified by:
- doubleValue in interface RealNumber
- Overrides:
- doubleValue in class java.lang.Number
floatValue
public float floatValue()
- Description copied from interface:
Returns the value of this number as a float
. This may
involve rounding.
- Specified by:
- floatValue in interface RealNumber
- Overrides:
- floatValue in class java.lang.Number
toBigDecimal
public java.math.BigDecimal toBigDecimal(int precision)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Converts the value of this number to a BigDecimal
with the
specified precision. This method uses the ROUND_HALF_UP
rounding mode as defined in BigDecimal
.
- Specified by:
- toBigDecimal in interface RealNumber
toBigInteger
public java.math.BigInteger toBigInteger()
- Description copied from interface:
Converts the value of this number to a BigInteger
. This
may involve rounding.
- Specified by:
- toBigInteger in interface RealNumber