jdk icon indicating copy to clipboard operation
jdk copied to clipboard

8331485: Odd Results when Parsing Scientific Notation with Large Exponent

Open justin-curtis-lu opened this issue 10 months ago • 6 comments

Please review this PR which corrects an edge case bug for java.text.DecimalFormat that causes incorrect parsing results for strings with very large exponent values.

When parsing values with large exponents, if the value of the exponent exceeds Integer.MAX_VALUE, the parsed value is equal to 0. If the value of the exponent exceeds Long.MAX_VALUE, the parsed value is equal to the mantissa. Both results are confusing and incorrect.

For example,

NumberFormat fmt = NumberFormat.getInstance(Locale.US);
fmt.parse(".1E2147483648"); // returns 0.0
fmt.parse(".1E9223372036854775808"); // returns 0.1
// For comparison
Double.parseDouble(".1E2147483648"); // returns Infinity
Double.parseDouble(".1E9223372036854775808"); // returns Infinity

After this change, both parse calls return Double.POSITIVE_INFINITY now.


Progress

  • [x] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • [x] Change must not contain extraneous whitespace
  • [x] Commit message must refer to an issue

Issue

  • JDK-8331485: Odd Results when Parsing Scientific Notation with Large Exponent (Bug - P4)

Reviewers

  • Naoto Sato (@naotoj - Reviewer) ⚠️ Review applies to bc391f96
  • @ahauschulte (no known openjdk.org user name / role) ⚠️ Review applies to 2c167493

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19075/head:pull/19075
$ git checkout pull/19075

Update a local copy of the PR:
$ git checkout pull/19075
$ git pull https://git.openjdk.org/jdk.git pull/19075/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19075

View PR using the GUI difftool:
$ git pr show -t 19075

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19075.diff

Webrev

Link to Webrev Comment

justin-curtis-lu avatar May 03 '24 08:05 justin-curtis-lu