Float.parseFloat doesn't currently round correctly, or even monotonically,
in certain cases.

In particular, the following test program prints false:


public class Foo {
  public static void main(String[] args) {
    System.out.println(144115196665790480f <= 144115196665790481f);
  }
}

A patch is attached, and can also be found at
https://bugs.openjdk.java.net/show_bug.cgi?id=100208.

There was a comment in sun.misc.FloatingDecimal claiming this would take
400 lines of code, but by eliminating the (fallacious) "sticky rounding"
logic, and just duplicating the double-parsing logic, it only ends up
costing ~40 net lines of code added.

The added code is mostly identical to the preexisting double-parsing code.

This is a prerequisite for the separate, previously sent patch improving
the performance of BigInteger.doubleValue() and floatValue().  (Testing for
that patch revealed this bug.)

Louis Wasserman
wasserman.lo...@gmail.com
http://profiles.google.com/wasserman.louis

Reply via email to