Skip to content

Commit

Permalink
Merge pull request #51 from xtonik/MANTISSA
Browse files Browse the repository at this point in the history
This looks good. Thank you very much for working out this improvement!
  • Loading branch information
wrandelshofer authored Oct 25, 2024
2 parents ec1a73c + ea1c8a9 commit 3ecdbbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -932,14 +932,14 @@ static double tryDecToDoubleWithFastAlgorithm(boolean isNegative, long significa
mantissa >>>= 1;

// Here we have mantissa < (1<<53), unless there was an overflow
if (mantissa >= (1L << DOUBLE_SIGNIFICAND_WIDTH)) {
if (mantissa == (1L << DOUBLE_SIGNIFICAND_WIDTH)) {
// This will happen when parsing values such as 7.2057594037927933e+16
mantissa = (1L << (DOUBLE_SIGNIFICAND_WIDTH - 1));
mantissa = 0;
lz--; // undo previous addition
} else {
mantissa &= ~(1L << (DOUBLE_SIGNIFICAND_WIDTH - 1));
}

mantissa &= ~(1L << (DOUBLE_SIGNIFICAND_WIDTH - 1));

long realExponent = exponent - lz;
// we have to check that realExponent is in range, otherwise we bail out
if ((realExponent < 1) || (realExponent > DOUBLE_MAX_EXPONENT_POWER_OF_TWO + DOUBLE_EXPONENT_BIAS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,14 @@ static float tryDecToFloatWithFastAlgorithm(boolean isNegative, long significand
mantissa >>>= 1;

// Here we have mantissa < (1<<24), unless there was an overflow
if (mantissa >= (1L << FLOAT_SIGNIFICAND_WIDTH)) {
// This will happen when parsing values such as 7.2057594037927933e+16 ??
mantissa = (1L << (FLOAT_SIGNIFICAND_WIDTH - 1));
if (mantissa == (1L << FLOAT_SIGNIFICAND_WIDTH)) {
// This will happen when parsing values such as 1.4757395E20
mantissa = 0;
lz--; // undo previous addition
} else {
mantissa &= ~(1L << (FLOAT_SIGNIFICAND_WIDTH - 1));
}

mantissa &= ~(1L << (FLOAT_SIGNIFICAND_WIDTH - 1));


long real_exponent = exponent - lz;
// we have to check that real_exponent is in range, otherwise we bail out
if ((real_exponent < 1) || (real_exponent > FLOAT_MAX_EXPONENT_POWER_OF_TWO + FLOAT_EXPONENT_BIAS)) {
Expand Down

0 comments on commit 3ecdbbe

Please sign in to comment.