Fix helper function for rounding numbers (#1702)

Fixes #1701

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
Robert Sipka
2017-04-03 08:44:46 +02:00
committed by GitHub
parent f0a7e2456a
commit 5f24620c8a
2 changed files with 8 additions and 3 deletions
@@ -153,8 +153,8 @@ ecma_builtin_number_prototype_helper_round (lit_utf8_byte_t *digits_p, /**< [in,
int i = 1;
/* Handle curry number. */
for (; i < (int) num_digits; i++)
/* Handle carry number. */
for (; i <= round_num; i++)
{
if (++digits_p[round_num - i] <= '9')
{
@@ -164,7 +164,7 @@ ecma_builtin_number_prototype_helper_round (lit_utf8_byte_t *digits_p, /**< [in,
}
/* Prepend highest digit */
if (i >= (int) num_digits)
if (i > round_num)
{
memmove (digits_p + 1, digits_p, num_digits);
digits_p[0] = '1';
@@ -36,6 +36,11 @@ assert((123456789012345678901.0).toPrecision("6") === "1.23457e+20");
assert((123.56).toPrecision(1.3) === "1e+2");
assert((123.56).toPrecision(21.9) === "123.560000000000000000");
assert(Number(982).toPrecision(1) === "1e+3");
assert(Number(982).toPrecision(2) === "9.8e+2");
assert(Number(1499).toPrecision(1) === "1e+3");
assert(Number(1500).toPrecision(1) === "2e+3");
try {
(12).toPrecision(0);
assert(false);