Bug 16640

Summary: Acid3 reveals broken behavior in toFixed and toExponential
Product: WebKit Reporter: Eric Seidel (no email) <eric>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: staikos
Priority: P2 Keywords: EasyFix
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.4   
Bug Depends on: 16643    
Bug Blocks:    
Attachments:
Description Flags
Test case for toFixed/toExponential
oliver: review+
Test case for toFixed/toExponential
none
Add more toFixed and toExponential tests, fix (-0).toFixed() and refactor a little
oliver: review+
Fix -0.toExponential() and printing of trailing 0s in toExponential
oliver: review+
Add more tests, including toPrecision
oliver: review+
Split tests into 3 files, fixed toPrecision(nan) handling
oliver: review+
Add toString testing for firefox compatibility oliver: review+

Eric Seidel (no email)
Reported 2007-12-28 02:15:09 PST
Acid3 reveals broken behavior in toFixed and toExponential This section of the test fails miserably: if ((0.0).toFixed(4) != "0.0000" || (-0.0).toFixed(4) != "0.0000") ok = false; if ((0.0).toExponential(4) != "0.0000e+0" || (-0.0).toExponential(4) != "0.0000e+0") ok = false; I can't imagine this is intentional. Current behavior: (0.0).toFixed(4) 0.0000 (-0.0).toFixed(4) 0.00-0 (0.0).toExponential(4) NaN (-0.0).toExponential(4) NaN
Attachments
Test case for toFixed/toExponential (1.18 KB, patch)
2007-12-28 02:39 PST, Eric Seidel (no email)
oliver: review+
Test case for toFixed/toExponential (1.18 KB, patch)
2007-12-28 15:13 PST, Eric Seidel (no email)
no flags
Add more toFixed and toExponential tests, fix (-0).toFixed() and refactor a little (4.81 KB, patch)
2007-12-28 15:13 PST, Eric Seidel (no email)
oliver: review+
Fix -0.toExponential() and printing of trailing 0s in toExponential (5.11 KB, patch)
2007-12-28 15:13 PST, Eric Seidel (no email)
oliver: review+
Add more tests, including toPrecision (5.52 KB, patch)
2007-12-28 15:13 PST, Eric Seidel (no email)
oliver: review+
Split tests into 3 files, fixed toPrecision(nan) handling (18.31 KB, patch)
2007-12-28 15:13 PST, Eric Seidel (no email)
oliver: review+
Add toString testing for firefox compatibility (24.15 KB, patch)
2007-12-28 15:13 PST, Eric Seidel (no email)
oliver: review+
Eric Seidel (no email)
Comment 1 2007-12-28 02:39:24 PST
Created attachment 18143 [details] Test case for toFixed/toExponential .../fast/js/resources/toFixed-and-toExponential.js | 6 ++++++ LayoutTests/fast/js/toFixed-and-toExponential.html | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
Eric Seidel (no email)
Comment 2 2007-12-28 02:39:51 PST
I don't have the energy tonight to actually make the fix, but the attached test case patch, makes it very clear what is broken.
Alexey Proskuryakov
Comment 3 2007-12-28 06:58:53 PST
Sounds like a duplicate of bug 5258 and bug 5259 (and yes, it's about time to fix those).
Eric Seidel (no email)
Comment 4 2007-12-28 15:13:08 PST
I have patches to fix bugs in our toFixed, toExponential and toPrecision implementations, as well as add test cases for toString.
Eric Seidel (no email)
Comment 5 2007-12-28 15:13:35 PST
Created attachment 18154 [details] Test case for toFixed/toExponential .../fast/js/resources/toFixed-and-toExponential.js | 6 ++++++ LayoutTests/fast/js/toFixed-and-toExponential.html | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
Eric Seidel (no email)
Comment 6 2007-12-28 15:13:37 PST
Created attachment 18155 [details] Add more toFixed and toExponential tests, fix (-0).toFixed() and refactor a little JavaScriptCore/kjs/number_object.cpp | 37 +++++++++++-------- .../fast/js/resources/toFixed-and-toExponential.js | 38 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 16 deletions(-)
Eric Seidel (no email)
Comment 7 2007-12-28 15:13:39 PST
Created attachment 18156 [details] Fix -0.toExponential() and printing of trailing 0s in toExponential JavaScriptCore/kjs/number_object.cpp | 51 +++++++++++-------- .../fast/js/resources/toFixed-and-toExponential.js | 5 ++ 2 files changed, 34 insertions(+), 22 deletions(-)
Eric Seidel (no email)
Comment 8 2007-12-28 15:13:41 PST
Created attachment 18157 [details] Add more tests, including toPrecision .../fast/js/resources/toFixed-and-toExponential.js | 66 ++++++++++++++++---- 1 files changed, 54 insertions(+), 12 deletions(-)
Eric Seidel (no email)
Comment 9 2007-12-28 15:13:44 PST
Created attachment 18158 [details] Split tests into 3 files, fixed toPrecision(nan) handling JavaScriptCore/kjs/number_object.cpp | 2 +- LayoutTests/fast/js/number-tofixed-expected.txt | 24 +++++ .../fast/js/number-toprecision-expected.txt | 26 +++++- .../fast/js/resources/number-toExponential.js | 43 +++++++++ LayoutTests/fast/js/resources/number-tofixed.js | 44 ++++++++++ .../fast/js/resources/number-toprecision.js | 38 ++++++++- .../fast/js/resources/toFixed-and-toExponential.js | 91 -------------------- LayoutTests/fast/js/toFixed-and-toExponential.html | 13 --- 8 files changed, 170 insertions(+), 111 deletions(-)
Eric Seidel (no email)
Comment 10 2007-12-28 15:13:46 PST
Created attachment 18159 [details] Add toString testing for firefox compatibility .../fast/js/number-toExponential-expected.txt | 27 ++++++++ LayoutTests/fast/js/number-toString-expected.txt | 58 +++++++++++++++++ LayoutTests/fast/js/number-toString.html | 13 ++++ LayoutTests/fast/js/resources/number-toString.js | 67 ++++++++++++++++++++ 4 files changed, 165 insertions(+), 0 deletions(-)
Eric Seidel (no email)
Comment 11 2007-12-28 15:14:23 PST
I should note that these patches depend on the patches attached to bug 16643.
Eric Seidel (no email)
Comment 12 2007-12-28 15:16:27 PST
*** Bug 5258 has been marked as a duplicate of this bug. ***
Eric Seidel (no email)
Comment 13 2007-12-28 15:16:58 PST
*** Bug 5259 has been marked as a duplicate of this bug. ***
Oliver Hunt
Comment 14 2007-12-28 18:41:07 PST
Comment on attachment 18156 [details] Fix -0.toExponential() and printing of trailing 0s in toExponential I don't believe you can safely check against -0.0 + if (x == -0.0) // (-0.0).toExponential() should print as 0 instead of -0 + x = 0;
Oliver Hunt
Comment 15 2007-12-28 18:44:35 PST
Comment on attachment 18159 [details] Add toString testing for firefox compatibility whoops Addition of failures == badness
Eric Seidel (no email)
Comment 16 2007-12-28 19:57:45 PST
Sunspider reports somewhat wild results (some faster some slower) as a result of these changes. None seem related, and I write it off as random gcc code-gen changes. :(
Eric Seidel (no email)
Comment 17 2007-12-28 19:59:42 PST
The overall sunspider result is: ** TOTAL **: ?? 3881.8ms +/- 0.2% 3886.3ms +/- 0.2% not conclusive: might be *1.001x as slow*
Note You need to log in before you can comment on or make changes to this bug.