Improvements to BigDecimal(double, MathContext) constructor

Claes Redestad claes.redestad at oracle.com
Thu Jul 7 16:52:51 UTC 2016


On 2016-07-07 18:18, John Platts wrote:
> Here is the current significand normalization loop below in the BigDecimal(double, MathContext) constructor:
>          // Normalize
>          while ((significand & 1) == 0) { // i.e., significand is even
>              significand >>= 1;
>              exponent++;
>          }
>
> Here is a better way to normalize the significand in the BigDecimal(double, MathContext) constructor:
>          int significandTz = Long.numberOfTrailingZeros(significand);
>          significand >>= significandTz;
>          exponent += significandTz;

Seems correct.

Do you have any benchmark showing an improvement from this change?

/Claes


More information about the core-libs-dev mailing list