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
FieldsModifier and TypeFieldDescriptionstatic final OmegaBigDecimalstatic final OmegaBigDecimalstatic final OmegaBigDecimalstatic final OmegaBigDecimalstatic final OmegaBigDecimal -
Constructor Summary
ConstructorsConstructorDescriptionOmegaBigDecimal(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 anOmegaBigDecimalwhose value is(this + augend).intdivide(BigDecimal divisor, MathContext mc) Returns aOmegaBigDecimalwhose value is(this / divisor), with rounding according to the context settings.doublebooleanCompares thisOmegaBigDecimalwith the specifiedObjectfor equality.floatinthashCode()Returns the hash code for thisOmegaBigDecimal.intintValue()booleanisFinite()booleanbooleanlongmax(OmegaBigDecimal val) Returns the maximum of thisOmegaBigDecimalandval.min(OmegaBigDecimal val) Returns the minimum of thisOmegaBigDecimalandval.multiply(OmegaBigDecimal multiplicand) Returns anOmegaBigDecimalwhose value isthis * multiplicand.negate()Returns the opposite of this number.pow(int n) Returns anOmegaBigDecimalwhose value isthis^n.subtract(OmegaBigDecimal subtrahend) Returns anOmegaBigDecimalwhose 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 thisOmegaBigDecimalwith the specifiedObjectfor equality. UnlikecompareTo, this method considers twoBigDecimalobjects 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:
equalsin classObject- Parameters:
x-Objectto which thisOmegaBigDecimalis to be compared.- Returns:
trueif and only if the specifiedObjectis anOmegaBigDecimaland 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 twoOmegaBigDecimalobjects 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:
floatValuein classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber
-
compareTo
- Specified by:
compareToin 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 anOmegaBigDecimalwhose 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 anOmegaBigDecimalwhose 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 anOmegaBigDecimalwhose value isthis * multiplicand. In case of a0 * +/- infinityindeterminate form, an exception is thrown.- Parameters:
multiplicand- value to be multiplied by thisOmegaBigDecimal.- Returns:
this * multiplicand
-
divide
Returns aOmegaBigDecimalwhose value is(this / divisor), with rounding according to the context settings.- Parameters:
divisor- value by which thisOmegaBigDecimalis 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 isUNNECESSARYormc.precision == 0and the quotient has a non-terminating decimal expansion.
-
min
Returns the minimum of thisOmegaBigDecimalandval.- Parameters:
val- value with which the minimum is to be computed.- Returns:
- the
OmegaBigDecimalwhose value is the lesser of thisOmegaBigDecimalandval. If they are equal, as defined by thecompareTomethod,thisis returned.
-
max
Returns the maximum of thisOmegaBigDecimalandval.- Parameters:
val- value with which the maximum is to be computed.- Returns:
- the
OmegaBigDecimalwhose value is the greater of thisOmegaBigDecimalandval. If they are equal, as defined by thecompareTomethod,thisis returned.
-
pow
Returns anOmegaBigDecimalwhose value isthis^n. The power is computed exactly, to unlimited precision.The parameter
nmust be in the range 0 through 999999999, inclusive.ZERO.pow(0)returnsONE.- Parameters:
n- power to raise thisBigDecimalto.- Returns:
this^n- Throws:
ArithmeticException- ifnis out of range.- Since:
- 1.5
-
isLeftNeighborhood
public boolean isLeftNeighborhood() -
isRightNeighborhood
public boolean isRightNeighborhood()
-