Replacement for snprintf
Walter Bright
newshound2 at digitalmars.com
Thu Oct 31 01:09:14 UTC 2019
Replacing snprintf for floating point is very challenging, because:
1. people have been improving snprintf for decades
2. people expect precision and performance
3. the standard is snprintf, any credible implementation must be the same or better
To that end, you'll need to be familiar with the following:
754-2019 IEEE Standard for Floating Point Arithmetic
https://ieeexplore.ieee.org/document/8766229
Printing Floating-Pointer Numbers Quickly and Accurately with Integers
https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
Printing Floating-Point Numbers
https://ranjitjhala.github.io/static/fp-printing-popl16.pdf
Ryu Fast Float To String Conversion
https://dl.acm.org/citation.cfm?id=3192369
https://github.com/ulfjack/ryu
http://www.zverovich.net/2019/02/11/formatting-floating-point-numbers.html
https://news.ycombinator.com/item?id=20181832
Jonathan Marler's D implementation of ryu:
https://github.com/dragon-lang/mar/blob/master/src/mar/ryu.d
For historical interest, here's DMC's version, which was state of the art in the
1980's:
https://github.com/DigitalMars/dmc/blob/master/src/core/floatcvt.c
More information about the Digitalmars-d
mailing list