Commit 7d2c7e3f authored by tkent@chromium.org's avatar tkent@chromium.org

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

        Reviewed by Darin Adler.

        Fix a bug that Math.round() retunrs incorrect results for huge integers
        https://bugs.webkit.org/show_bug.cgi?id=34462

        * runtime/MathObject.cpp:
        (JSC::mathProtoFuncRound): Avoid "arg + 0.5".

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

        Reviewed by Darin Adler.

        Fix a bug that Math.round() retunrs incorrect results for huge integers
        https://bugs.webkit.org/show_bug.cgi?id=34462

        * fast/js/math-expected.txt:
        * fast/js/script-tests/math.js: Add test cases for Math.round() for huge numbers.

git-svn-id: svn://svn.chromium.org/blink/trunk@54197 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d3dd007c
2010-02-01 Kent Tamura <tkent@chromium.org>
Reviewed by Darin Adler.
Fix a bug that Math.round() retunrs incorrect results for huge integers
https://bugs.webkit.org/show_bug.cgi?id=34462
* runtime/MathObject.cpp:
(JSC::mathProtoFuncRound): Avoid "arg + 0.5".
2010-02-01 Kwang Yul Seo <skyul@company100.net>
Reviewed by Eric Seidel.
......
......@@ -218,7 +218,8 @@ JSValue JSC_HOST_CALL mathProtoFuncRound(ExecState* exec, JSObject*, JSValue, co
double arg = args.at(0).toNumber(exec);
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));
}
JSValue JSC_HOST_CALL mathProtoFuncSin(ExecState* exec, JSObject*, JSValue, const ArgList& args)
......
2010-02-01 Kent Tamura <tkent@chromium.org>
Reviewed by Darin Adler.
Fix a bug that Math.round() retunrs incorrect results for huge integers
https://bugs.webkit.org/show_bug.cgi?id=34462
* fast/js/math-expected.txt:
* fast/js/script-tests/math.js: Add test cases for Math.round() for huge numbers.
2010-02-01 Dmitry Titov <dimich@chromium.org>
Reviewed by David Levin.
......
......@@ -130,6 +130,17 @@ PASS Math.round(1.5) is 2
PASS Math.round(-1.5) is -1
PASS Math.round(1.6) is 2
PASS Math.round(-1.6) is -2
PASS Math.round(8640000000000000) is 8640000000000000
PASS Math.round(8640000000000000.5) is 8640000000000000
PASS Math.round(8640000000000001) is 8640000000000001
PASS Math.round(8640000000000002) is 8640000000000002
PASS Math.round(9007199254740990) is 9007199254740990
PASS Math.round(9007199254740991) is 9007199254740991
PASS Math.round(-8640000000000000) is -8640000000000000
PASS Math.round(-8640000000000001) is -8640000000000001
PASS Math.round(-8640000000000002) is -8640000000000002
PASS Math.round(-9007199254740990) is -9007199254740990
PASS Math.round(-9007199254740991) is -9007199254740991
PASS Math.round(Infinity) is Infinity
PASS Math.round(-Infinity) is -Infinity
PASS Math.sin(NaN) is NaN
......
......@@ -191,6 +191,18 @@ shouldBe("Math.round(1.5)", "2");
shouldBe("Math.round(-1.5)", "-1");
shouldBe("Math.round(1.6)", "2");
shouldBe("Math.round(-1.6)", "-2");
shouldBe("Math.round(8640000000000000)", "8640000000000000");
// The following is expected. Double can't represent .5 in this case.
shouldBe("Math.round(8640000000000000.5)", "8640000000000000");
shouldBe("Math.round(8640000000000001)", "8640000000000001");
shouldBe("Math.round(8640000000000002)", "8640000000000002");
shouldBe("Math.round(9007199254740990)", "9007199254740990");
shouldBe("Math.round(9007199254740991)", "9007199254740991");
shouldBe("Math.round(-8640000000000000)", "-8640000000000000");
shouldBe("Math.round(-8640000000000001)", "-8640000000000001");
shouldBe("Math.round(-8640000000000002)", "-8640000000000002");
shouldBe("Math.round(-9007199254740990)", "-9007199254740990");
shouldBe("Math.round(-9007199254740991)", "-9007199254740991");
shouldBe("Math.round(Infinity)", "Infinity");
shouldBe("Math.round(-Infinity)", "-Infinity");
......
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