JDK 7u-dev review request 8024356: Double.parseDouble() is slow for long Strings
david.r.chase at oracle.com
Thu Sep 12 20:00:34 UTC 2013
On 2013-09-12, at 1:17 AM, Dmitry Nadezhin <dmitry.nadezhin at gmail.com> wrote:
> The optimal constant for double conversion could be 768 ,
> the optimal constant for float conversion could be 142,
> but I leave this optimization to JDK 9.
It would be helpful to mention in the proof/comment, that 768 refers to the
decimal representation that has had leading zeroes between decimal point
and mantissa trimmed.
An exact case is the decimal representation of the sum of
2^-1022 + 2^-1075
This has a decimal point, then 307 zeroes, non-zeroes at 308 (2) and 1075 (5)
(and usually non-zeroes between) for a span of 768 decimal digits between
the leading and trailing zeroes. (There are other screw cases. Here, 2^-1022
is the minimum normalized-rep double, and 2^-1075 is 1/2 ulp for doubles
with binary exponent -1022, which is represented as 1 in IEEE format.)
Appending any trailing non-zero on this decimal representation rounds up; nothing trailing rounds down.
If the final digit 5 is instead a 6, it always rounds up, if it is a 4 it always rounds down no matter what is appended.
There are other screw cases, but they always involve 2^-1075 because that requires
the maximum number of decimal digits for its representation.
More information about the core-libs-dev