Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2a4e550
add Array#toString (WIP)
MaxGraey Sep 19, 2018
9e6c7de
use Array#join for toString internally
MaxGraey Sep 19, 2018
e269a0e
update (WIP)
MaxGraey Sep 19, 2018
96125e2
add tests for sub-arrays (WIP)
MaxGraey Sep 19, 2018
1b46367
add definisions
MaxGraey Sep 19, 2018
527a57d
fix tslint
MaxGraey Sep 19, 2018
ca2bdeb
update test's builds
MaxGraey Sep 19, 2018
9711df9
disable no-unsafe-any per-line
MaxGraey Sep 19, 2018
b918779
refactoring & optimizations
MaxGraey Sep 19, 2018
e9baecc
add more tests
MaxGraey Sep 19, 2018
1488301
handle booleans
MaxGraey Sep 19, 2018
dbefc9b
improve count digits in itoa
MaxGraey Sep 20, 2018
a493326
use faster divede & conquer approach for decimal calculations
MaxGraey Sep 20, 2018
225f55d
refactoring & simplifications for itoa
MaxGraey Sep 20, 2018
4643507
implementing "dtoa" (WIP)
MaxGraey Sep 20, 2018
eb00cba
update (wip)
MaxGraey Sep 20, 2018
f423094
update (wip)
MaxGraey Sep 20, 2018
3620242
fix lint
MaxGraey Sep 20, 2018
f86a863
fix Array#join case for floats
MaxGraey Sep 20, 2018
adaf0d3
more fixes
MaxGraey Sep 20, 2018
1ac0920
update (wip)
MaxGraey Sep 21, 2018
4c00ac8
fixes (wip)
MaxGraey Sep 21, 2018
dba7761
more fixes (wip)
MaxGraey Sep 21, 2018
7a5ec23
cleanups (wip)
MaxGraey Sep 21, 2018
ba78526
minor improvments (wip)
MaxGraey Sep 21, 2018
c68f26e
refactoring (wip)
MaxGraey Sep 21, 2018
4dbae43
refactor itoa
MaxGraey Sep 21, 2018
9086bc0
initial tests (wip)
MaxGraey Sep 21, 2018
810a89a
minor optimizations
MaxGraey Sep 21, 2018
2615084
minor improvments & refactoring
MaxGraey Sep 22, 2018
68b2d55
implement prettify for dtoa (wip)
MaxGraey Sep 22, 2018
1e927bd
fix genExponent (wip)
MaxGraey Sep 22, 2018
8d56b54
fix prettify for negative values (wip)
MaxGraey Sep 22, 2018
3d42f0e
update (wip)
MaxGraey Sep 22, 2018
72a86e9
deallocate tmp buffer
MaxGraey Sep 22, 2018
c4f1ff8
add basic tests (wip)
MaxGraey Sep 22, 2018
678de64
more tests (wip)
MaxGraey Sep 22, 2018
2c5d49b
more tests + fixes (wip)
MaxGraey Sep 22, 2018
749c34a
more tests (wip)
MaxGraey Sep 22, 2018
430d68d
more tests (wip)
MaxGraey Sep 22, 2018
4190233
cleanups
MaxGraey Sep 22, 2018
013bc0d
minor optimize globals (wip)
MaxGraey Sep 22, 2018
b8dfcb2
optimizations
MaxGraey Sep 22, 2018
65cb8a9
minor tweaks
MaxGraey Sep 22, 2018
64187fb
more tweaks
MaxGraey Sep 22, 2018
6939844
add f64 tests for Array#join
MaxGraey Sep 23, 2018
a9213e3
improvments (wip)
MaxGraey Sep 23, 2018
1ddbd1e
add basic single float tests for dtoa
MaxGraey Sep 23, 2018
99843d2
add some final comments
MaxGraey Sep 23, 2018
9a6b6f2
finalize
MaxGraey Sep 23, 2018
65a45b8
fix Array#join for references (wip)
MaxGraey Sep 24, 2018
d2a6a11
update tests
MaxGraey Sep 24, 2018
36397d9
unify itoa and dtoa in one file "internal/number"
MaxGraey Sep 24, 2018
d487877
minor improvments for Array#join (wip)
MaxGraey Sep 24, 2018
ca9fa43
optimize bool serialization (wip)
MaxGraey Sep 24, 2018
2bb9514
avoid string concat (wip)
MaxGraey Sep 25, 2018
0fbd6be
fixes (wip)
MaxGraey Sep 25, 2018
293f9a4
avoid string concat (wip)
MaxGraey Sep 25, 2018
d24dfdc
minor improvments (wip)
MaxGraey Sep 25, 2018
4bb3da7
fix tslint issues
MaxGraey Sep 25, 2018
3882492
avoid string concat (wip)
MaxGraey Sep 25, 2018
c0aaf1b
reuse indexOf for includes and minor refactoring internals
MaxGraey Sep 25, 2018
c74c477
avoid string concat progress (wip)
MaxGraey Sep 25, 2018
8c41cde
add more tests (wip)
MaxGraey Sep 25, 2018
f78ded0
finalize
MaxGraey Sep 25, 2018
e59d192
refactoring
MaxGraey Sep 25, 2018
c545609
add more tests for dtoa
MaxGraey Sep 25, 2018
3d95859
add comment about imprecise issue
MaxGraey Sep 26, 2018
4acb8cc
minor refactoring
MaxGraey Sep 26, 2018
46957b1
minor improvment
MaxGraey Oct 1, 2018
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
Prev Previous commit
Next Next commit
finalize
  • Loading branch information
MaxGraey committed Sep 23, 2018
commit 9a6b6f20099613599c7a1e40b6fe19487572153f
15 changes: 9 additions & 6 deletions std/assembly/internal/dtoa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ function prettify(buffer: usize, length: i32, k: i32): i32 {
} else if (length == 1) {
// 1e30
store<u16>(buffer, CharCode.e, STRING_HEADER_SIZE + 2);
return genExponent(buffer + 4, kk - 1) + 2;
length = genExponent(buffer + 4, kk - 1);
return length + 2;
} else {
let len = length << 1;
memory.copy(
Expand All @@ -307,23 +308,25 @@ function prettify(buffer: usize, length: i32, k: i32): i32 {
);
store<u16>(buffer, CharCode.DOT, STRING_HEADER_SIZE + 2);
store<u16>(buffer + len, CharCode.e, STRING_HEADER_SIZE + 2);
let expLen = genExponent(buffer + len + 4, kk - 1);
return length + expLen + 2;
length += genExponent(buffer + len + 4, kk - 1);
return length + 2;
}
}

export function dtoa_core(buffer: usize, value: f64): i32 {
var sign = <i32>(value < 0);
value = abs(value);
if (sign) {
value = -value;
store<u16>(buffer, CharCode.MINUS, STRING_HEADER_SIZE);
}
// assert(value > 0 && value <= 1.7976931348623157e308);
var len = grisu2(value, buffer, sign);
len = prettify(buffer + (sign << 1), len - sign, _K);
if (sign) store<u16>(buffer, CharCode.MINUS, STRING_HEADER_SIZE);
return len + sign;
}

export function dtoa(value: f64): String {
if (value == 0) return "0.0"; // or should be "0" following js semantics?
if (value == 0) return "0.0";
if (!isFinite(value)) {
if (isNaN(value)) return "NaN";
return select<String>("-Infinity", "Infinity", value < 0);
Expand Down
Loading