[webkit-reviews] review requested: [Bug 9697] parseInt results may be inaccurate for numbers greater than 2^53 : [Attachment 15541] Revised proposed patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jul 17 02:43:50 PDT 2007

Cameron Zwarich (cpst) <cwzwarich at uwaterloo.ca> has asked  for review:
Bug 9697: parseInt results may be inaccurate for numbers greater than 2^53

Attachment 15541: Revised proposed patch

------- Additional Comments from Cameron Zwarich (cpst)
<cwzwarich at uwaterloo.ca>
I fixed the problems mentioned in Darin's comments and added some test cases.
Here are some explanations of the cases that are maybe not as obvious:

(- 'infinity').toString()

This should be NaN, but will be Infinity if we don't check for the first three
letters. Note, this doesn't happen in the current version of toDouble(), but
that is because the current code will also miss things like "1e2000", which
should be Infinity but instead are NaN.

00000000000000', 16)

This test and the one below demonstrate the necessity of the test for
radixMultiplier being infinite in the loop in parseIntOverflow(). If the
radixMultiplier becomes infinite, then the arithmetic below will make number
become NaN if any digit is zero. Hence we explicitly test for this in the code.
I added the decimal case as well for posterity, even though that is now handled
by strtod().


These will give Infinity unless we check the input of strtod(). The second
demonstrates the necessity of checking for the decimal point as well.

The only test that will not fail no matter what changes to the code take place
between the current code and the code in my patch is the one testing the value


The hexadecimal conversion code in toDouble() is slightly different than
elsewhere, so it rounds differently and converts this correctly, but it fails
for other cases in the JS Core tests that are now fixed. I figured I'd add the
test in anyways since I  added it for the lexer and parseInt().

I believe that accounts for every branch.

More information about the webkit-reviews mailing list