Skip to content

Commit 818c9cd

Browse files
authored
Fix issue #742 (#1650)
It is a workaround fix. The problem comes from the inaccuracy of the double rounding. JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
1 parent 202a88b commit 818c9cd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,15 @@ ecma_builtin_number_prototype_object_to_string (ecma_value_t this_arg, /**< this
253253
scale = -scale;
254254
}
255255

256-
int buff_size;
256+
int buff_size = 1;
257257
if (is_scale_negative)
258258
{
259-
buff_size = (int) floor (log (this_arg_number) / log (radix)) + 1;
259+
double counter = this_arg_number;
260+
while (counter > radix)
261+
{
262+
counter /= radix;
263+
buff_size++;
264+
}
260265
}
261266
else
262267
{

tests/jerry/number-prototype-to-string.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ assert((123400).toString(34) === "34pe");
8080
assert((123400).toString(35) === "2upp");
8181
assert((123400).toString(36) === "2n7s");
8282

83+
assert ((1152921504606846600).toString([1,2,3,4].slice(1,2)) === "111111111111111111111111111111111111111111111111111010000000");
84+
assert ((-1152921504606846600).toString(2) === "-111111111111111111111111111111111111111111111111111010000000");
85+
86+
assert ((0x100000000000061).toString(2) === "100000000000000000000000000000000000000000000000001100000")
87+
assert ((-0x100000000000061).toString(16) === "-100000000000060");
88+
8389
assert((123400).toString(new Number(16)) === "1e208");
8490

8591
var digit_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',

0 commit comments

Comments
 (0)