Package org.oristool.math
Class OmegaBigDecimal
java.lang.Object
java.lang.Number
org.oristool.math.OmegaBigDecimal
- All Implemented Interfaces:
Serializable
,Comparable<OmegaBigDecimal>
Immutable, arbitrary-precision signed decimal numbers with positive and
negative infinity. Every actual computation is delegated to a
java.math.BigDecimal
instance.
All methods and constructors for this class throw
NullPointerException
when passed a null
object reference for
any input parameter.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final OmegaBigDecimal
static final OmegaBigDecimal
static final OmegaBigDecimal
static final OmegaBigDecimal
static final OmegaBigDecimal
-
Constructor Summary
ConstructorDescriptionOmegaBigDecimal
(long number) OmegaBigDecimal
(String number) Parses a number from the input string.OmegaBigDecimal
(BigDecimal number) -
Method Summary
Modifier and TypeMethodDescriptionabs()
Returns the absolute value of this number.add
(OmegaBigDecimal augend) Returns anOmegaBigDecimal
whose value is(this + augend)
.int
divide
(BigDecimal divisor, MathContext mc) Returns aOmegaBigDecimal
whose value is(this / divisor)
, with rounding according to the context settings.double
boolean
Compares thisOmegaBigDecimal
with the specifiedObject
for equality.float
int
hashCode()
Returns the hash code for thisOmegaBigDecimal
.int
intValue()
boolean
isFinite()
boolean
boolean
long
max
(OmegaBigDecimal val) Returns the maximum of thisOmegaBigDecimal
andval
.min
(OmegaBigDecimal val) Returns the minimum of thisOmegaBigDecimal
andval
.multiply
(OmegaBigDecimal multiplicand) Returns anOmegaBigDecimal
whose value isthis * multiplicand
.negate()
Returns the opposite of this number.pow
(int n) Returns anOmegaBigDecimal
whose value isthis^n
.subtract
(OmegaBigDecimal subtrahend) Returns anOmegaBigDecimal
whose value is(this - subtrahend)
.Returns the left neighborhood of this value.Returns the right neighborhood of this value.toString()
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
POSITIVE_INFINITY
-
NEGATIVE_INFINITY
-
ZERO
-
ONE
-
TEN
-
-
Constructor Details
-
OmegaBigDecimal
Parses a number from the input string.- Parameters:
number
- a string
-
OmegaBigDecimal
-
OmegaBigDecimal
public OmegaBigDecimal(long number)
-
-
Method Details
-
toLeftNeighborhood
Returns the left neighborhood of this value.- Returns:
- left neighborhood
-
toRightNeighborhood
Returns the right neighborhood of this value.- Returns:
- right neighborhood
-
toString
-
equals
Compares thisOmegaBigDecimal
with the specifiedObject
for equality. UnlikecompareTo
, this method considers twoBigDecimal
objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method). Positive (or negative) infinity is considered equal to itself.- Overrides:
equals
in classObject
- Parameters:
x
-Object
to which thisOmegaBigDecimal
is to be compared.- Returns:
true
if and only if the specifiedObject
is anOmegaBigDecimal
and either its value and scale are equal to thisOmegaBigDecimal
's or they are both positive (negative) infinity.- See Also:
-
hashCode
public int hashCode()Returns the hash code for thisOmegaBigDecimal
. Note that twoOmegaBigDecimal
objects that are numerically equal but differ in scale (like 2.0 and 2.00) will have the same hash code (this is different wrt BigDecimal). Positive (negative) infinity objects always have the same hash code. -
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Specified by:
floatValue
in classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValue
in classNumber
-
compareTo
- Specified by:
compareTo
in interfaceComparable<OmegaBigDecimal>
-
isFinite
public boolean isFinite() -
bigDecimalValue
-
abs
Returns the absolute value of this number.- Returns:
- absolute value
-
negate
Returns the opposite of this number.- Returns:
- opposite
-
add
Returns anOmegaBigDecimal
whose value is(this + augend)
. In case of a +infinity -infinity indeterminate form, an exception is thrown.- Parameters:
augend
- value to be added to this number- Returns:
this + augend
-
subtract
Returns anOmegaBigDecimal
whose value is(this - subtrahend)
. In case of a +infinity -infinity indeterminate form, an exception is thrown.- Parameters:
subtrahend
- value to be subtracted from thisOmegaBigDecimal
.- Returns:
this - subtrahend
-
multiply
Returns anOmegaBigDecimal
whose value isthis * multiplicand
. In case of a0 * +/- infinity
indeterminate form, an exception is thrown.- Parameters:
multiplicand
- value to be multiplied by thisOmegaBigDecimal
.- Returns:
this * multiplicand
-
divide
Returns aOmegaBigDecimal
whose value is(this / divisor)
, with rounding according to the context settings.- Parameters:
divisor
- value by which thisOmegaBigDecimal
is to be divided.mc
- the context to use.- Returns:
this / divisor
, rounded as necessary.- Throws:
IllegalArgumentException
- if the divisor is BigDecimal.ZEROArithmeticException
- if the result is inexact but the rounding mode isUNNECESSARY
ormc.precision == 0
and the quotient has a non-terminating decimal expansion.
-
min
Returns the minimum of thisOmegaBigDecimal
andval
.- Parameters:
val
- value with which the minimum is to be computed.- Returns:
- the
OmegaBigDecimal
whose value is the lesser of thisOmegaBigDecimal
andval
. If they are equal, as defined by thecompareTo
method,this
is returned.
-
max
Returns the maximum of thisOmegaBigDecimal
andval
.- Parameters:
val
- value with which the maximum is to be computed.- Returns:
- the
OmegaBigDecimal
whose value is the greater of thisOmegaBigDecimal
andval
. If they are equal, as defined by thecompareTo
method,this
is returned.
-
pow
Returns anOmegaBigDecimal
whose value isthis^n
. The power is computed exactly, to unlimited precision.The parameter
n
must be in the range 0 through 999999999, inclusive.ZERO.pow(0)
returnsONE
.- Parameters:
n
- power to raise thisBigDecimal
to.- Returns:
this^n
- Throws:
ArithmeticException
- ifn
is out of range.- Since:
- 1.5
-
isLeftNeighborhood
public boolean isLeftNeighborhood() -
isRightNeighborhood
public boolean isRightNeighborhood()
-