Overview | Package | Class | Tree | Deprecated | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
negate()
--
Computes -thisinvert()
--
Computes 1/thisadd(RealNumber)
--
Computes this+nsubtract(RealNumber)
--
Computes this-nmultiply(RealNumber)
--
Computes this*ndivide(RealNumber)
--
Computes this/npow(RealNumber)
--
Computes this**nExamples of real numbers are 3, -1.68, the square root of 3, 2/3, pi, 18.2**2.3 and e.
Real numbers can be cast to native Java numbers with these conversion methods:
longValue()
--
Converts this number to a long
.
Use fitsLong()
to make sure
the conversion will succeedintValue()
--
Converts this number to an int
.
Use fitsInt()
to make sure
the conversion will succeedshortValue()
--
Converts this number to a short
. Use
fitsShort()
to make sure
the conversion will succeedbyteValue()
--
Converts this number to a byte
.
Use fitsByte()
to make sure
the conversion will succeeddoubleValue()
--
Converts this number to a double
.
Use fitsDouble()
to make sure
the conversion will succeedfloatValue()
--
Converts this number to a float
.
Use fitsFloat()
to make sure
the conversion will succeedUse the NumberCentral
to obtain RealNumber
instances. For instance:
RealNumber n =
NumberCentral.valueOf(0.399);
Concrete implementations of this interface should implement
the boolean equals(Object)
method derived from
java.lang.Object
in order to compare RealNumber
instances for equality.
PENDING (1): The names of the following methods may be changed in the near future to reflect the expected change in the syntax of the Java language syntax to include operator overloading based on method names:
PENDING (2): Rounding modes different from trunc should be specified. Method names may include roundUp, roundDown etc. if this is in accordance with proposed changes to language syntax (See: "The Evolution of Numerical Computing in Java" by James Gosling, available from the Sun JavaSoft website.)
Method Summary | |
RealNumber | abs()
Computes |this|. |
RealNumber | add(RealNumber n)
Computes this+n, where n is a real number. |
byte | byteValue()
Returns the value of this number as a byte . |
int | compareTo(RealNumber n)
Returns -1, 0 or 1 as this number is less than, equal to, or greater than n, where n is a real number. |
RealNumber | divide(RealNumber n)
Computes this/n, where n is a real number. |
double | doubleValue()
Returns the value of this number as a double . |
boolean | fitsByte()
Determines if the truncated value of this number fits in a byte . |
boolean | fitsDouble()
Determines if the rounded value of this number fits in a double . |
boolean | fitsFloat()
Determines if the rounded value of this number fits in a float . |
boolean | fitsInt()
Determines if the truncated value of this number fits in an int . |
boolean | fitsLong()
Determines if the truncated value of this number fits in a long . |
boolean | fitsShort()
Determines if the truncated value of this number fits in a short . |
float | floatValue()
Returns the value of this number as a float . |
int | getSign()
Determines the sign of this number. |
int | intValue()
Returns the value of this number as an int . |
RealNumber | invert()
Computes 1/this. |
long | longValue()
Returns the value of this number as a long . |
RealNumber | multiply(RealNumber n)
Computes this*n, where n is a real number. |
RealNumber | negate()
Computes -this. |
RealNumber | pow(RealNumber n)
Computes this**n, where n is a real number. |
int | retryCompare(RealNumber n)
Returns -1, 0 or 1 as this number is less than, equal to, or greater than n, where n is a real number. |
short | shortValue()
Returns the value of this number as a short . |
RealNumber | subtract(RealNumber n)
Computes this-n, where n is a real number. |
java.math.BigDecimal | toBigDecimal(int precision)
Converts the value of this number to a BigDecimal with the
specified precision. |
java.math.BigDecimal | toBigDecimal(int precision,
int roundingMode)
Converts the value of this number to a BigDecimal with the
specified precision and rounding mode. |
java.math.BigInteger | toBigInteger()
Converts the value of this number to a BigInteger . |
IntegerNumber | trunc()
Rounds to an integer number towards 0. |
Method Detail |
public int getSign()
public int compareTo(RealNumber n) throws java.lang.IllegalArgumentException, CanNotCompareException
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
.
n
- the number to compare to.null
.public int retryCompare(RealNumber n) throws java.lang.IllegalArgumentException, CanNotCompareException
CanNotCompareException
is thrown.
n
- the number to compare to.null
.public RealNumber abs()
public RealNumber negate()
public RealNumber invert() throws java.lang.ArithmeticException
public RealNumber add(RealNumber n) throws java.lang.IllegalArgumentException
n
- the number to add to this.null
.public RealNumber subtract(RealNumber n) throws java.lang.IllegalArgumentException
n
- the number to subtract from this.null
.public RealNumber multiply(RealNumber n) throws java.lang.IllegalArgumentException
n
- the factor, the number to multiply this by.null
.public RealNumber divide(RealNumber n) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException
n
- the number to divide this by.null
.public RealNumber pow(RealNumber n) throws java.lang.IllegalArgumentException
n
- the exponent.null
.public boolean fitsLong()
long
.true
iff this value fits in a long
.public boolean fitsInt()
int
.true
iff this value fits in an int
.public boolean fitsShort()
short
.true
iff this value fits in a short
.public boolean fitsByte()
byte
.true
iff this value fits in a byte
.public boolean fitsDouble()
double
.true
iff this value fits in a double
.public boolean fitsFloat()
float
.true
iff this value fits in a float
.public long longValue()
long
. This may
involve rounding.long
.public int intValue()
int
. This may
involve rounding.int
.public short shortValue()
short
. This may
involve rounding.short
.public byte byteValue()
byte
. This may
involve rounding.byte
.public double doubleValue()
double
. This may
involve rounding.double
.public float floatValue()
float
. This may
involve rounding.float
.public java.math.BigDecimal toBigDecimal(int precision) throws java.lang.IllegalArgumentException
BigDecimal
with the
specified precision. This method uses the ROUND_HALF_UP
rounding mode as defined in BigDecimal
.
precision
- the number of digits behind the decimal point.BigDecimal
with the rounded value of this.public java.math.BigDecimal toBigDecimal(int precision, int roundingMode) throws java.lang.IllegalArgumentException
BigDecimal
with the
specified precision and rounding mode.
precision
- the number of digits behind the decimal point.
roundingMode
- the rounding mode to use, one of the modes defined
in class BigDecimal
.BigDecimal
with the rounded value of this.BigDecimal
public java.math.BigInteger toBigInteger()
BigInteger
. This
may involve rounding.BigInteger
.public IntegerNumber trunc()
Overview | Package | Class | Tree | Deprecated | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |