Commit 191b3814 authored by tkent@chromium.org's avatar tkent@chromium.org

2010-01-31 Kent Tamura <tkent@chromium.org>

        Reviewed by Darin Adler.

        [Windows] Fix a bug of round() with huge integral numbers
        https://bugs.webkit.org/show_bug.cgi?id=34297

        Fix a bug that round() for huge integral numbers returns incorrect
        results. For example, round(8639999913600001) returns
        8639999913600002 without this change though the double type can
        represent 8639999913600001 precisely.

        Math.round() of JavaScript has a similar problem. But this change
        doesn't fix it because Math.round() doesn't use round() of
        MathExtra.h.

        * wtf/MathExtras.h:
        (round): Avoid to do "num + 0.5" or "num - 0.5".
        (roundf): Fixed similarly.
        (llround): Calls round().
        (llroundf): Calls roundf().
        (lround): Calls round().
        (lroundf): Calls roundf().

2010-01-31  Kent Tamura  <tkent@chromium.org>

        Reviewed by Darin Adler.

        [Win] Fix a bug of round() with huge integral numbers
        https://bugs.webkit.org/show_bug.cgi?id=34297

        Add a test case to call round(8639999913600001).

        * fast/forms/input-valueasnumber-datetime-expected.txt:
        * fast/forms/script-tests/input-valueasnumber-datetime.js:

git-svn-id: svn://svn.chromium.org/blink/trunk@54121 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c0a3ea6d
2010-01-31 Kent Tamura <tkent@chromium.org>
Reviewed by Darin Adler.
[Windows] Fix a bug of round() with huge integral numbers
https://bugs.webkit.org/show_bug.cgi?id=34297
Fix a bug that round() for huge integral numbers returns incorrect
results. For example, round(8639999913600001) returns
8639999913600002 without this change though the double type can
represent 8639999913600001 precisely.
Math.round() of JavaScript has a similar problem. But this change
doesn't fix it because Math.round() doesn't use round() of
MathExtra.h.
* wtf/MathExtras.h:
(round): Avoid to do "num + 0.5" or "num - 0.5".
(roundf): Fixed similarly.
(llround): Calls round().
(llroundf): Calls roundf().
(lround): Calls round().
(lroundf): Calls roundf().
2010-01-29 Mark Rowe <mrowe@apple.com>
Sort Xcode projects.
......
......@@ -98,12 +98,25 @@ inline bool signbit(double x) { struct ieee_double *p = (struct ieee_double *)&x
#if COMPILER(MSVC) || COMPILER(RVCT)
inline long long llround(double num) { return static_cast<long long>(num > 0 ? num + 0.5 : ceil(num - 0.5)); }
inline long long llroundf(float num) { return static_cast<long long>(num > 0 ? num + 0.5f : ceil(num - 0.5f)); }
inline long lround(double num) { return static_cast<long>(num > 0 ? num + 0.5 : ceil(num - 0.5)); }
inline long lroundf(float num) { return static_cast<long>(num > 0 ? num + 0.5f : ceilf(num - 0.5f)); }
inline double round(double num) { return num > 0 ? floor(num + 0.5) : ceil(num - 0.5); }
inline float roundf(float num) { return num > 0 ? floorf(num + 0.5f) : ceilf(num - 0.5f); }
// We must not do 'num + 0.5' or 'num - 0.5' because they can cause precision loss.
static double round(double num)
{
double integer = ceil(num);
if (num > 0)
return integer - num > 0.5 ? integer - 1.0 : integer;
return integer - num >= 0.5 ? integer - 1.0 : integer;
}
static float roundf(float num)
{
float integer = ceilf(num);
if (num > 0)
return integer - num > 0.5f ? integer - 1.0f : integer;
return integer - num >= 0.5f ? integer - 1.0f : integer;
}
inline long long llround(double num) { return static_cast<long long>(round(num)); }
inline long long llroundf(float num) { return static_cast<long long>(roundf(num)); }
inline long lround(double num) { return static_cast<long>(round(num)); }
inline long lroundf(float num) { return static_cast<long>(roundf(num)); }
inline double trunc(double num) { return num > 0 ? floor(num) : ceil(num); }
#endif
......
2010-01-31 Kent Tamura <tkent@chromium.org>
Reviewed by Darin Adler.
[Win] Fix a bug of round() with huge integral numbers
https://bugs.webkit.org/show_bug.cgi?id=34297
Add a test case to call round(8639999913600001).
* fast/forms/input-valueasnumber-datetime-expected.txt:
* fast/forms/script-tests/input-valueasnumber-datetime.js:
2010-01-31 Kent Tamura <tkent@chromium.org>
Reviewed by Darin Adler.
......
......@@ -14,6 +14,7 @@ PASS setValueAsNumberAndGetValue(10000, 0, 1, 12, 0, 1, 0) is "10000-01-01T12:00
PASS setValueAsNumberAndGetValue(794, 9, 22, 0, 0, 0, 0) is ""
PASS setValueAsNumberAndGetValue(1582, 9, 14, 23, 59, 59, 999) is ""
PASS setValueAsNumberAndGetValue(1582, 9, 15, 0, 0, 0, 0) is "1582-10-15T00:00Z"
PASS setValueAsNumberAndGetValue(275760, 8, 12, 0, 0, 0, 1) is "275760-09-12T00:00:00.001Z"
PASS setValueAsNumberAndGetValue(275760, 8, 13, 0, 0, 0, 0) is "275760-09-13T00:00Z"
Tests to set invalid values to valueAsNumber:
PASS input.value = ""; input.valueAsNumber = null; input.value is "1970-01-01T00:00Z"
......
......@@ -26,6 +26,7 @@ shouldBe('setValueAsNumberAndGetValue(10000, 0, 1, 12, 0, 1, 0)', '"10000-01-01T
shouldBe('setValueAsNumberAndGetValue(794, 9, 22, 0, 0, 0, 0)', '""');
shouldBe('setValueAsNumberAndGetValue(1582, 9, 14, 23, 59, 59, 999)', '""');
shouldBe('setValueAsNumberAndGetValue(1582, 9, 15, 0, 0, 0, 0)', '"1582-10-15T00:00Z"');
shouldBe('setValueAsNumberAndGetValue(275760, 8, 12, 0, 0, 0, 1)', '"275760-09-12T00:00:00.001Z"');
shouldBe('setValueAsNumberAndGetValue(275760, 8, 13, 0, 0, 0, 0)', '"275760-09-13T00:00Z"');
// Date.UTC() of V8 throws an exception for the following value though JavaScriptCore doesn't.
// shouldBe('setValueAsNumberAndGetValue(275760, 8, 13, 0, 0, 0, 1)', '"275760-09-13T00:00:00.001Z"');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment