final class Rounding extends Object
DecimalRounding
and
TruncatedPart
.Modifier and Type | Method and Description |
---|---|
static int |
calculateRoundingIncrement(DecimalRounding rounding,
int sign,
long truncatedValue,
int firstTruncatedDigit,
boolean zeroAfterFirstTruncatedDigit)
Returns the rounding increment appropriate for the specified
rounding . |
static int |
calculateRoundingIncrement(DecimalRounding rounding,
long truncatedValue,
long truncatedDigits,
long one)
Returns the rounding increment appropriate for the specified
rounding given the remaining truncated digits truncated by modulo
one. |
static int |
calculateRoundingIncrementForDivision(DecimalRounding rounding,
long truncatedValue,
long truncatedDigits,
long divisor)
Returns the rounding increment appropriate for the specified
rounding given the remaining truncated digits truncated by a
given divisor. |
static TruncatedPart |
truncatedPartFor(long nonNegativeRemainder,
long nonNegativeDivisor)
Returns a truncated part constant given a non-negative remainder
resulting from a division by the given non-negative divisor.
|
static TruncatedPart |
truncatedPartFor2pow63(long remainder)
Returns a truncated part constant given a non-negative remainder
resulting from a division by 2^63
|
static TruncatedPart |
truncatedPartFor2pow64(long remainder)
Returns a truncated part constant given a non-negative remainder
resulting from a division by 2^64
|
static TruncatedPart |
truncatedPartFor2powN(long remainder,
int n)
Returns a truncated part constant given a non-negative remainder
resulting from a division by 2^n
|
static TruncatedPart |
truncatedPartFor2powN(long hRemainder,
long lRemainder,
int n)
Returns a truncated part constant given a non-negative 128 bit remainder
resulting from a division by 2^n
|
static TruncatedPart |
truncatedPartForScale19(long remainder)
Returns a truncated part constant given a non-negative remainder
resulting from a division by 10^19.
|
public static final int calculateRoundingIncrement(DecimalRounding rounding, int sign, long truncatedValue, int firstTruncatedDigit, boolean zeroAfterFirstTruncatedDigit)
rounding
. The returned value is one of -1, 0 or 1.rounding
- the rounding mode to applysign
- the sign of the total value, either +1 or -1; determines the
result value if roundedtruncatedValue
- the truncated result before rounding is applied (only used for
HALF_EVEN rounding)firstTruncatedDigit
- the first truncated digit, must be in [0, 1, ..., 9]
zeroAfterFirstTruncatedDigit
- true if all truncated digits after the first truncated digit
are zero, and false otherwisetruncatedValue
to get the rounded
result, one of -1, 0 or 1public static final int calculateRoundingIncrementForDivision(DecimalRounding rounding, long truncatedValue, long truncatedDigits, long divisor)
rounding
given the remaining truncated digits truncated by a
given divisor. The returned value is one of -1, 0 or 1.rounding
- the rounding mode to applytruncatedValue
- the truncated result before rounding is applied (only used for
HALF_EVEN rounding)truncatedDigits
- the truncated part, it most hold that
abs(truncatedDigits) < abs(divisor)
divisor
- the divisor that led to the truncated digitstruncatedValue
to get the rounded
result, one of -1, 0 or 1public static final int calculateRoundingIncrement(DecimalRounding rounding, long truncatedValue, long truncatedDigits, long one)
rounding
given the remaining truncated digits truncated by modulo
one. The returned value is one of -1, 0 or 1.rounding
- the rounding mode to applytruncatedValue
- the truncated result before rounding is applied (only used for
HALF_EVEN rounding)truncatedDigits
- the truncated part of a double, must be >-one
and
<one
one
- the value representing 1 which is 10^scale
, must be
>= 10
truncatedValue
to get the rounded
result, one of -1, 0 or 1public static final TruncatedPart truncatedPartFor(long nonNegativeRemainder, long nonNegativeDivisor)
nonNegativeRemainder
- the remainder part, not negative and
nonNegativeRemainder < nonNegativeDivisor
nonNegativeDivisor
- the divisor, not negative or LONG.MIN_VALUE --- the latter
equal to abs(Long.MIN_VALUE)
public static final TruncatedPart truncatedPartForScale19(long remainder)
remainder
- the remainder partpublic static final TruncatedPart truncatedPartFor2powN(long remainder, int n)
remainder
- the remainder partn
- the power of 2 of the divisor, n > 0
public static final TruncatedPart truncatedPartFor2powN(long hRemainder, long lRemainder, int n)
hRemainder
- the high bits of the remainder partlRemainder
- the low bits of the remainder partn
- the power of 2 of the divisor, n > 0
public static final TruncatedPart truncatedPartFor2pow63(long remainder)
remainder
- the remainder partpublic static final TruncatedPart truncatedPartFor2pow64(long remainder)
remainder
- the remainder part