Remix.run Logo
jhallenworld 7 hours ago

I have been using Walter Bright's libc code from Zortech-C for microcontrollers, where I care about code size more than anything else:

https://github.com/nklabs/libnklabs/blob/main/src/nkprintf_f... https://github.com/nklabs/libnklabs/blob/main/src/nkstrtod.c https://github.com/nklabs/libnklabs/blob/main/src/nkdectab.c

nkprintf_fp.c+nkdectab.c: 2494 bytes

schubfach.cc: 10K bytes.. the code is small, but there is a giant table of numbers. Also this is just dtoa, not a full printf formatter.

OTOH, the old code is not round-trip accurate.

Russ Cox should make a C version of his code..

nigeltao 5 hours ago | parent | next [-]

> Russ Cox should make a C version of his code.

https://github.com/rsc/fpfmt/blob/main/bench/uscalec/ftoa.c

vitaut 2 hours ago | parent [-]

Note that it has the same table of powers of 10: https://github.com/rsc/fpfmt/blob/main/bench/uscalec/pow10.h

vitaut 2 hours ago | parent | prev [-]

It is possible to compress the table using the technique from Dragonbox (https://github.com/fmtlib/fmt/blob/8b8fccdad40decf68687ec038...) at the cost of some perf. It's on my TODO list for zmij.