public abstract class AbstractArithmetic extends Object implements DecimalArithmetic
scale
, rounding mode
and overflow mode
.Constructor and Description |
---|
AbstractArithmetic() |
Modifier and Type | Method and Description |
---|---|
int |
compare(long uDecimal1,
long uDecimal2)
Compares two unscaled decimal values numerically.
|
int |
compareToUnscaled(long uDecimal,
long unscaled,
int scale)
Compares two unscaled decimal values numerically.
|
DecimalArithmetic |
deriveArithmetic(int scale)
Derives an arithmetic instance for the specified
scale using this arithmetic's rounding mode and overflow mode . |
DecimalArithmetic |
deriveArithmetic(OverflowMode overflowMode)
Derives an arithmetic instance for the same
scale as this arithmetic but for the specified
overflowMode . |
DecimalArithmetic |
deriveArithmetic(RoundingMode roundingMode)
Derives an arithmetic instance for the same
scale as this arithmetic but for the specified
roundingMode . |
DecimalArithmetic |
deriveArithmetic(RoundingMode roundingMode,
OverflowMode overflowMode)
Derives an arithmetic instance for the same
scale as this arithmetic but for the specified
roundingMode and overflowMode . |
DecimalArithmetic |
deriveArithmetic(TruncationPolicy truncationPolicy)
Derives an arithmetic instance for the same
scale as this arithmetic but with rounding and
overflow mode specified by the given truncationPolicy . |
long |
fromBigInteger(BigInteger value)
Converts the specified
BigInteger value to an unscaled decimal. |
int |
signum(long uDecimal)
Returns the signum function of the specified unscaled decimal.
|
BigDecimal |
toBigDecimal(long uDecimal)
Converts the specified unscaled decimal value into a
BigDecimal value using this arithmetic's
scale for the result value. |
BigDecimal |
toBigDecimal(long uDecimal,
int scale)
Converts the specified unscaled decimal value into a
BigDecimal value using the specified scale
for the result value. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
abs, add, addLong, addUnscaled, avg, divide, divideByLong, divideByPowerOf10, divideByUnscaled, fromBigDecimal, fromDouble, fromFloat, fromLong, fromUnscaled, getOverflowMode, getRoundingMode, getScale, getScaleMetrics, getTruncationPolicy, invert, multiply, multiplyByLong, multiplyByPowerOf10, multiplyByUnscaled, negate, one, parse, parse, pow, round, shiftLeft, shiftRight, sqrt, square, subtract, subtractLong, subtractUnscaled, toDouble, toFloat, toLong, toString, toString, toUnscaled
public AbstractArithmetic()
public final DecimalArithmetic deriveArithmetic(int scale)
DecimalArithmetic
scale
using this arithmetic's rounding mode
and overflow mode
.deriveArithmetic
in interface DecimalArithmetic
scale
- the scale for the new arithmetic; must be in [0,18]
both ends inclusiveScales.getScaleMetrics(int)
,
ScaleMetrics.getArithmetic(RoundingMode)
,
ScaleMetrics.getArithmetic(TruncationPolicy)
public final DecimalArithmetic deriveArithmetic(RoundingMode roundingMode)
DecimalArithmetic
scale
as this arithmetic but for the specified
roundingMode
. The returned arithmetic uses the same overflow mode
as this
arithmetic.deriveArithmetic
in interface DecimalArithmetic
roundingMode
- the rounding mode for the new arithmeticpublic final DecimalArithmetic deriveArithmetic(RoundingMode roundingMode, OverflowMode overflowMode)
DecimalArithmetic
scale
as this arithmetic but for the specified
roundingMode
and overflowMode
.deriveArithmetic
in interface DecimalArithmetic
roundingMode
- the rounding mode for the new arithmeticoverflowMode
- the overflow mode for the new arithmeticpublic final DecimalArithmetic deriveArithmetic(OverflowMode overflowMode)
DecimalArithmetic
scale
as this arithmetic but for the specified
overflowMode
. The returned arithmetic uses the same rounding mode
as this
arithmetic.deriveArithmetic
in interface DecimalArithmetic
overflowMode
- the overflow mode for the new arithmeticpublic final DecimalArithmetic deriveArithmetic(TruncationPolicy truncationPolicy)
DecimalArithmetic
scale
as this arithmetic but with rounding and
overflow mode specified by the given truncationPolicy
.deriveArithmetic
in interface DecimalArithmetic
truncationPolicy
- the truncation policy specifying rounding and overflow mode for the new arithmeticpublic final int signum(long uDecimal)
DecimalArithmetic
signum
in interface DecimalArithmetic
uDecimal
- the unscaled decimalpublic final int compare(long uDecimal1, long uDecimal2)
DecimalArithmetic
compare
in interface DecimalArithmetic
uDecimal1
- the first unscaled decimal to compareuDecimal2
- the second unscaled decimal to compare0
if unscaled1 == unscaled2
; a value less than 0
if
unscaled1 < unscaled2
; and a value greater than 0
if unscaled1 > unscaled2
public final int compareToUnscaled(long uDecimal, long unscaled, int scale)
DecimalArithmetic
scale
whereas the scale of the second unscaled
value is explicitly
specified by the scale
argument.compareToUnscaled
in interface DecimalArithmetic
uDecimal
- the first unscaled decimal to compareunscaled
- the second unscaled decimal to comparescale
- the scale of unscaled
0
if unscaled1 == unscaled2
; a value less than 0
if
unscaled1 < unscaled2
; and a value greater than 0
if unscaled1 > unscaled2
public final long fromBigInteger(BigInteger value)
DecimalArithmetic
BigInteger
value to an unscaled decimal. An exception is thrown if the specified
value is too large to be represented as a Decimal of this arithmetic's scale
.fromBigInteger
in interface DecimalArithmetic
value
- the value to convertpublic final BigDecimal toBigDecimal(long uDecimal)
DecimalArithmetic
BigDecimal
value using this arithmetic's
scale
for the result value.
Note: this operation is not strictly garbage free since the result value is usually allocated; however no temporary objects other than the result are allocated during the conversion.
toBigDecimal
in interface DecimalArithmetic
uDecimal
- the unscaled decimal value to convert into a BigDecimal
valueuDecimal
value converted into a BigDecimal
valuepublic final BigDecimal toBigDecimal(long uDecimal, int scale)
DecimalArithmetic
BigDecimal
value using the specified scale
for the result value. The arithmetic's rounding mode
is applied if rounding is
necessary.
Note: this operation is not garbage free since the result value is usually allocated and also temporary objects may be allocated during the conversion. Note however that temporary objects are only allocated if the unscaled value of the result exceeds the range of a long value.
toBigDecimal
in interface DecimalArithmetic
uDecimal
- the unscaled decimal value to convert into a BigDecimal
valuescale
- the scale to use for the resulting BigDecimal
valueuDecimal
value converted into a BigDecimal
value, possibly rounded or truncated