Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,8 +1505,10 @@ double js_atod(const char *str, const char **pnext, int radix, int flags,
}

/* Use the extra digits for rounding if the base is a power of
two. Otherwise they are just truncated. */
if (radix_bits != 0 && extra_digits != 0) {
two. Otherwise use them as a sticky bit so that round-half-to-even
rounds correctly when there are non-zero digits beyond the
precision we kept. */
if (extra_digits != 0) {
tmp0->tab[0] |= 1;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/test_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ function test_number()

assert((1.3).toString(7), "1.2046204620462046205");
assert((1.3).toString(35), "1.ahhhhhhhhhm");

/* parsing must use digits beyond max_digits as a sticky bit so
that round-half-to-even rounds in the correct direction.
https://github.com/bellard/quickjs/issues/452 */
assert(+"100000000000000000000000.000000000000001",
1.0000000000000001e+23);
}

function test_eval2()
Expand Down