Summary: | Fix a bug that Math.round() returns incorrect results for huge integers | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Kent Tamura <tkent> | ||||
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | darin | ||||
Priority: | P2 | ||||||
Version: | 528+ (Nightly build) | ||||||
Hardware: | All | ||||||
OS: | All | ||||||
Attachments: |
|
Description
Kent Tamura
2010-02-01 19:37:14 PST
Created attachment 47901 [details]
Patch
Comment on attachment 47901 [details]
Patch
How about this instead?
- if (signbit(arg) && arg >= -0.5)
- return jsNumber(exec, -0.0);
- return jsNumber(exec, floor(arg + 0.5));
+ double integer = ceil(arg);
+ return jsNumber(exec, integer - (integer - arg > 0.5));
Comment on attachment 47901 [details]
Patch
Patch seems fine. But you should consider my patch with ceil that avoids the need for the separate if statement. You could use ? : instead of the way I did it. Or use my code exactly as is (as long as it passes your tests).
Would be nice to have tests cases for the maximum and minimum double values as well to make sure they don't turn into infinity when rounded. |