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, waitabs, 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, toUnscaledpublic AbstractArithmetic()
public final DecimalArithmetic deriveArithmetic(int scale)
DecimalArithmeticscale using this arithmetic's rounding mode and overflow mode.deriveArithmetic in interface DecimalArithmeticscale - 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)
DecimalArithmeticscale as this arithmetic but for the specified
roundingMode. The returned arithmetic uses the same overflow mode as this
arithmetic.deriveArithmetic in interface DecimalArithmeticroundingMode - the rounding mode for the new arithmeticpublic final DecimalArithmetic deriveArithmetic(RoundingMode roundingMode, OverflowMode overflowMode)
DecimalArithmeticscale as this arithmetic but for the specified
roundingMode and overflowMode.deriveArithmetic in interface DecimalArithmeticroundingMode - the rounding mode for the new arithmeticoverflowMode - the overflow mode for the new arithmeticpublic final DecimalArithmetic deriveArithmetic(OverflowMode overflowMode)
DecimalArithmeticscale as this arithmetic but for the specified
overflowMode. The returned arithmetic uses the same rounding mode as this
arithmetic.deriveArithmetic in interface DecimalArithmeticoverflowMode - the overflow mode for the new arithmeticpublic final DecimalArithmetic deriveArithmetic(TruncationPolicy truncationPolicy)
DecimalArithmeticscale as this arithmetic but with rounding and
overflow mode specified by the given truncationPolicy.deriveArithmetic in interface DecimalArithmetictruncationPolicy - the truncation policy specifying rounding and overflow mode for the new arithmeticpublic final int signum(long uDecimal)
DecimalArithmeticsignum in interface DecimalArithmeticuDecimal - the unscaled decimalpublic final int compare(long uDecimal1, long uDecimal2)
DecimalArithmeticcompare in interface DecimalArithmeticuDecimal1 - 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 > unscaled2public final int compareToUnscaled(long uDecimal, long unscaled, int scale)
DecimalArithmeticscale whereas the scale of the second unscaled value is explicitly
specified by the scale argument.compareToUnscaled in interface DecimalArithmeticuDecimal - the first unscaled decimal to compareunscaled - the second unscaled decimal to comparescale - the scale of unscaled0 if unscaled1 == unscaled2; a value less than 0 if
unscaled1 < unscaled2; and a value greater than 0 if unscaled1 > unscaled2public final long fromBigInteger(BigInteger value)
DecimalArithmeticBigInteger 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 DecimalArithmeticvalue - the value to convertpublic final BigDecimal toBigDecimal(long uDecimal)
DecimalArithmeticBigDecimal 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 DecimalArithmeticuDecimal - the unscaled decimal value to convert into a BigDecimal valueuDecimal value converted into a BigDecimal valuepublic final BigDecimal toBigDecimal(long uDecimal, int scale)
DecimalArithmeticBigDecimal 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 DecimalArithmeticuDecimal - 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