Class nl.coffee.math.Sum
java.lang.Object
|
+--java.lang.Number
|
+--nl.coffee.math.AbstractRealNumber
|
+--nl.coffee.math.AbstractCompositeNumber
|
+--nl.coffee.math.Sum
- public class Sum
- extends AbstractCompositeNumber
A sum of two real numbers.
Instances of Sum
must be obtained by using one of the
createInstance()
factory methods.
- Since:
- JUMP_1.0
- Version:
- 1.1 199809.24
- Author:
- Ernst de Haan
- See Also:
- Serialized Form
Field Summary
|
int
|
sign
The sign of this sum. |
Method Summary
|
static Sum
|
createInstance(RealNumber a,
RealNumber b)
Returns a Sum with the specified operands. |
static int
|
determineSign(RealNumber a,
RealNumber b)
Computes the sign of a sum with the specified operands. |
int
|
getSign()
Determines the sign of this 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. |
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.lang.String
|
toString()
Returns a textual representation of this object. |
IntegerNumber
|
trunc()
Rounds to an integer number towards 0. |
Methods inherited from class nl.coffee.math.AbstractRealNumber |
abs, add, byteValue, compareTo, divide, doubleValue, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, hashCode, intValue, invert, longValue, multiply, negate, pow, retryCompare, shortValue, subtract, toBigDecimal, toBigInteger |
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 |
sign
protected int sign
- The sign of this sum. This field is set only once upon construction.
Sum
protected Sum(RealNumber a,
RealNumber b)
throws java.lang.IllegalArgumentException
- Constructs a
Sum
based on the 2 specified operands.
- Parameters:
operand1
- the first operand for the sum.
operand2
- the second operand for the sum.- Throws:
- java.lang.IllegalArgumentException - if one of the following applies:
- a ==
null
- b ==
null
createInstance
public static Sum createInstance(RealNumber a,
RealNumber b)
throws java.lang.IllegalArgumentException
- Returns a
Sum
with the specified operands.
- Parameters:
a
- the first operand.
b
- the second operand.- Returns:
- the
Sum
instance, possibly newly constructed. - Throws:
- java.lang.IllegalArgumentException - if either argument is
null
.
determineSign
protected static int determineSign(RealNumber a,
RealNumber b)
throws CanNotCompareException
- Computes the sign of a sum with the specified operands.
- Parameters:
operand1
- the first operand.
operand2
- the second operand.
getSign
public int getSign()
- Determines the sign of this number. This method returns -1, 0, or
1 as this number is negative, zero, or positive.
- Returns:
- the sign of this number.
retryCompare
public int retryCompare(RealNumber n)
throws java.lang.IllegalArgumentException,
CanNotCompareException
- Returns -1, 0 or 1 as this number is less than, equal to, or greater
than n, where n is a real number.
- Parameters:
n
- the number to compare to.- Returns:
- -1 if this<n, 0 if this==n, 1 if
this>n.
- Throws:
- java.lang.IllegalArgumentException - if the argument is
null
. - Overrides:
- retryCompare in class AbstractRealNumber
toBigDecimal
public java.math.BigDecimal toBigDecimal(int precision,
int roundingMode)
throws java.lang.IllegalArgumentException
- Converts the value of this number to a
BigDecimal
with the
specified precision and rounding mode.
- Parameters:
precision
- the number of digits behind the decimal point.
roundingMode
- the rounding mode to use, one of the modes defined
in class BigDecimal
.- Returns:
- a
BigDecimal
with the rounded value of this. - Throws:
- java.lang.IllegalArgumentException - if precision<0 or
the rounding mode is not one of the valid rounding modes defined in
class
BigDecimal
.
trunc
public IntegerNumber trunc()
- Rounds to an integer number towards 0.
- Returns:
- this number truncated to an integer.
toString
public java.lang.String toString()
- Returns a textual representation of this object.
- Returns:
- a
String
representation of this object. - Overrides:
- toString in class java.lang.Object