8374202: Simplify significand normalization in BigDecimal(double, MathContext) constructor

Reviewed-by: rgiulietti
This commit is contained in:
Daisuke Yamazaki 2026-03-30 12:58:07 +00:00 committed by Raffaello Giulietti
parent 7e0a1499ee
commit d58fb1e290

View File

@ -1026,12 +1026,11 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
return;
}
// Normalize
while ((significand & 1) == 0) { // i.e., significand is even
significand >>= 1;
exponent++;
}
int scl = 0;
int nTrailingZeros = Long.numberOfTrailingZeros(significand);
significand >>= nTrailingZeros;
exponent += nTrailingZeros;
// Calculate intVal and scale
int scl = 0;
BigInteger rb;
long compactVal = sign * significand;
if (exponent == 0) {