Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing case for 10 digits in decimalCount64 #785

Merged
merged 2 commits into from
Aug 23, 2019
Merged
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
3 changes: 2 additions & 1 deletion std/assembly/util/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export function decimalCount32(value: u32): u32 {
export function decimalCount64(value: u64): u32 {
if (value < 1000000000000000) {
if (value < 1000000000000) {
return select<u32>(11, 12, value < 100000000000);
let m = select<u32>(11, 12, value < 100000000000);
return select<u32>(10, m, value < 10000000000);
} else {
let m = select<u32>(14, 15, value < 100000000000000);
return select<u32>(13, m, value < 10000000000000);
Expand Down
5 changes: 5 additions & 0 deletions tests/compiler/resolve-access.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,17 @@
end
)
(func $~lib/util/number/decimalCount64 (; 7 ;) (type $FUNCSIG$ij) (param $0 i64) (result i32)
i32.const 10
i32.const 11
i32.const 12
local.get $0
i64.const 100000000000
i64.lt_u
select
local.get $0
i64.const 10000000000
i64.lt_u
select
i32.const 13
i32.const 14
i32.const 15
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/resolve-access.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,13 @@
i64.const 100000000000
i64.lt_u
select
local.set $1
i32.const 10
local.get $1
local.get $0
i64.const 10000000000
i64.lt_u
select
return
else
i32.const 14
Expand Down
5 changes: 5 additions & 0 deletions tests/compiler/std/array.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -9581,12 +9581,17 @@
local.get $1
)
(func $~lib/util/number/decimalCount64 (; 181 ;) (type $FUNCSIG$ij) (param $0 i64) (result i32)
i32.const 10
i32.const 11
i32.const 12
local.get $0
i64.const 100000000000
i64.lt_u
select
local.get $0
i64.const 10000000000
i64.lt_u
select
i32.const 13
i32.const 14
i32.const 15
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/std/array.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -15001,6 +15001,13 @@
i64.const 100000000000
i64.lt_u
select
local.set $1
i32.const 10
local.get $1
local.get $0
i64.const 10000000000
i64.lt_u
select
return
else
i32.const 14
Expand Down
941 changes: 596 additions & 345 deletions tests/compiler/std/string.optimized.wat

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion tests/compiler/std/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,16 @@ assert(str.slice(0, -1) == "abcdefghijklm");
assert(itoa32(0) == "0");
assert(itoa32(1) == "1");
assert(itoa32(8) == "8");
assert(itoa32(12) == "12");
assert(itoa32(123) == "123");
assert(itoa32(-1000) == "-1000");
assert(itoa32(1234) == "1234");
assert(itoa32(12345) == "12345");
assert(itoa32(123456) == "123456");
assert(itoa32(1111111) == "1111111");
assert(itoa32(1234567) == "1234567");
assert(itoa32(12345678) == "12345678");
assert(itoa32(123456789) == "123456789");
assert(itoa32(0x7ffffffe) == "2147483646");
assert(itoa32(0x7fffffff) == "2147483647");
assert(itoa32(0x80000000) == "-2147483648");
Expand All @@ -266,20 +269,31 @@ assert(utoa32(0x80000000) == "2147483648");
assert(utoa32(u32.MAX_VALUE) == "4294967295");

assert(utoa64(0) == "0");
assert(utoa64(12) == "12");
assert(utoa64(123) == "123");
assert(utoa64(1234) == "1234");
assert(utoa64(12345) == "12345");
assert(utoa64(123456) == "123456");
assert(utoa64(1234567) == "1234567");
assert(utoa64(99999999) == "99999999");
assert(utoa64(100000000) == "100000000");
assert(utoa64(0xffffffff) == "4294967295");
assert(utoa64(4294967297) == "4294967297");
assert(utoa64(0xfffffffff) == "68719476735");
assert(utoa64(868719476735) == "868719476735");
assert(utoa64(8687194767350) == "8687194767350");
assert(utoa64(86871947673501) == "86871947673501");
assert(utoa64(999868719476735) == "999868719476735");
assert(utoa64(9999868719476735) == "9999868719476735");
assert(utoa64(19999868719476735) == "19999868719476735");
assert(utoa64(u64.MAX_VALUE) == "18446744073709551615");
assert(utoa64(129999868719476735) == "129999868719476735");
assert(utoa64(1239999868719476735) == "1239999868719476735");
assert(utoa64(u64.MAX_VALUE) == "18446744073709551615");

assert(itoa64(0) == "0");
assert(itoa64(-1234) == "-1234");
assert(itoa64(0xffffffff) == "4294967295");
assert(itoa64(4294967297) == "4294967297");
assert(itoa64(-0xffffffff) == "-4294967295");
assert(itoa64(68719476735) == "68719476735");
assert(itoa64(-68719476735) == "-68719476735");
Expand Down
923 changes: 588 additions & 335 deletions tests/compiler/std/string.untouched.wat

Large diffs are not rendered by default.