public abstract class AbstractUncheckedScale0fArithmetic extends AbstractUncheckedArithmetic
Scale0f
, that is, for longs.Constructor and Description |
---|
AbstractUncheckedScale0fArithmetic() |
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) . |
long |
fromLong(long value)
Converts the specified long value to an unscaled decimal.
|
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 |
multiply(long uDecimal1,
long uDecimal2)
Returns an unscaled decimal whose value is the product of the specified arguments:
(uDecimal1 * uDecimal2) . |
long |
one()
Returns the unscaled decimal for the decimal value
1 . |
long |
square(long uDecimal)
Returns an unscaled decimal whose value is the square of the specified argument: uDecimal2.
|
long |
subtractLong(long uDecimal,
long lValue)
Returns an unscaled decimal whose value is the difference of the specified arguments:
(uDecimal - lValue)
. |
long |
toLong(long uDecimal)
Converts the specified unscaled decimal value into a long value and returns it.
|
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, fromUnscaled, getRoundingMode, invert, multiplyByPowerOf10, multiplyByUnscaled, parse, parse, pow, round, shiftLeft, shiftRight, sqrt, subtractUnscaled, toDouble, toFloat, toUnscaled
public AbstractUncheckedScale0fArithmetic()
public 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 long multiply(long uDecimal1, long uDecimal2)
DecimalArithmetic
(uDecimal1 * uDecimal2)
. If rounding must be performed, this arithmetic's rounding mode
is applied.
Mathematically the method calculates round((uDecimal1 * uDecimal2) * 10-scale) avoiding information loss due to overflow of intermediary results.
uDecimal1
- first unscaled decimal value to be multiplieduDecimal2
- second unscaled decimal value to be multipliedround(uDecimal1 * uDecimal2)
public final long square(long uDecimal)
DecimalArithmetic
rounding mode
is applied.
Mathematically the method calculates round((uDecimal * uDecimal) * 10-scale) avoiding information loss due to overflow of intermediary results.
uDecimal
- the unscaled decimal value to be squaredround(uDecimal * uDecimal)
public final long fromLong(long value)
DecimalArithmetic
scale
.value
- the value to convertpublic final long toLong(long uDecimal)
DecimalArithmetic
rounding mode
is applied if rounding is necessary.uDecimal
- the unscaled decimal value to convert into a long valueuDecimal
value converted into a long value, possibly rounded or truncatedpublic 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