public abstract class AbstractUncheckedScaleNfArithmetic extends AbstractUncheckedArithmetic
Constructor and Description |
---|
AbstractUncheckedScaleNfArithmetic(ScaleMetrics scaleMetrics)
Constructor with scale metrics for this arithmetic.
|
Modifier and Type | Method and Description |
---|---|
long |
addLong(long uDecimal,
long lValue)
Returns an unscaled decimal whose value is the sum of the specified arguments:
(uDecimal + lValue) . |
int |
getScale()
Returns the scale
f applied to all unscaled decimal values passed to and returned by this
DecimalArithmetic . |
ScaleMetrics |
getScaleMetrics()
Returns the scale metrics associated with this decimal arithmetic object.
|
long |
one()
Returns the unscaled decimal for the decimal value
1 . |
long |
subtractLong(long uDecimal,
long lValue)
Returns an unscaled decimal whose value is the difference of the specified arguments:
(uDecimal - lValue)
. |
String |
toString(long uDecimal)
Converts the specified unscaled decimal value into a
String and returns it. |
void |
toString(long uDecimal,
Appendable appendable)
Converts the specified unscaled decimal value into a
String and appends the string to the
appendable . |
abs, add, getOverflowMode, getTruncationPolicy, multiplyByLong, negate, subtract
compare, compareToUnscaled, deriveArithmetic, deriveArithmetic, deriveArithmetic, deriveArithmetic, deriveArithmetic, fromBigInteger, signum, toBigDecimal, toBigDecimal
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addUnscaled, avg, divide, divideByLong, divideByPowerOf10, divideByUnscaled, fromBigDecimal, fromDouble, fromFloat, fromLong, fromUnscaled, getRoundingMode, invert, multiply, multiplyByPowerOf10, multiplyByUnscaled, parse, parse, pow, round, shiftLeft, shiftRight, sqrt, square, subtractUnscaled, toDouble, toFloat, toLong, toUnscaled
public AbstractUncheckedScaleNfArithmetic(ScaleMetrics scaleMetrics)
scaleMetrics
- the scale metricspublic final ScaleMetrics getScaleMetrics()
DecimalArithmetic
public final int getScale()
DecimalArithmetic
f
applied to all unscaled decimal values passed to and returned by this
DecimalArithmetic
. Corresponds to the number of digits to the right of the decimal point (cannot be
negative).
A given Decimal
value multiplied with 10f results in an unscaled long value.
Conversely, a Decimal
value d
can be computed from the unscaled value u
as
d = u*10-f.
f
applied to unscaled decimal values within this DecimalArithmetic
objectScaleMetrics.getScale()
public final long one()
DecimalArithmetic
1
. One is the value 10scale which
is also the multiplier used to get the unscaled decimal from the true decimal value.public final long addLong(long uDecimal, long lValue)
DecimalArithmetic
(uDecimal + lValue)
.
Mathematically the method calculates (uDecimal + lValue * 10scale) avoiding information loss due to overflow of intermediary results.
uDecimal
- unscaled decimal value to be addedlValue
- long value to be addedpublic final long subtractLong(long uDecimal, long lValue)
DecimalArithmetic
(uDecimal - lValue)
.
Mathematically the method calculates (uDecimal - lValue * 10scale) avoiding information loss due to overflow of intermediary results.
uDecimal
- unscaled decimal value to subtract fromlValue
- long value to subtractpublic final String toString(long uDecimal)
DecimalArithmetic
String
and returns it. If the scale
is zero, the conversion is identical to Long.toString(long)
. For all other scales a value with
exactly scale
fraction digits is returned even if some trailing fraction digits are zero.
Note: this operation is not strictly garbage free since the result value is allocated; however no
temporary objects other than the result are allocated during the conversion (internally a ThreadLocal
StringBuilder
object is used to construct the string value, which may become garbage if the thread
becomes garbage).
uDecimal
- the unscaled decimal value to convert into a String
uDecimal
value as into a String
public final void toString(long uDecimal, Appendable appendable) throws IOException
DecimalArithmetic
String
and appends the string to the
appendable
.
If the scale
is zero, the conversion into a string is identical to
Long.toString(long)
. For all other scales a string value with exactly scale
fraction digits is
created even if some trailing fraction digits are zero.
Note: this operation is not strictly garbage free since internally, a ThreadLocal
string builder
is used to construct the string. The ThreadLocal
value may become garbage if the thread becomes garbage.
uDecimal
- the unscaled decimal value to convert into a String
appendable
- the appendable to which the string representation of the unscaled decimal value is to be appendedIOException
- If an I/O error occurs when appending to appendable