printf() metaprogramming challenge
Walter Bright
newshound2 at digitalmars.com
Fri May 24 22:59:10 UTC 2019
On 5/24/2019 2:07 PM, Jonathan Marler wrote:
> It took me about an hour to port this "float to string" implementation to D:
>
> https://github.com/ulfjack/ryu
> https://github.com/dragon-lang/mar/blob/master/src/mar/ryu.d
https://github.com/ulfjack/ryu says: "The Java implementation differs from the
output of Double.toString in some cases: sometimes the output is shorter (which
is arguably more accurate) and sometimes the output may differ in the precise
digits output" which I find fairly concerning. Please review the paper I linked
to in my reply to Jacob.
Floating point formatting is not something that can be knocked out in an hour.
You can get a "mostly working" implementation that way, but not a serious,
robust, correct implementation with the expected flexibility. (And the test
cases to prove it correct.)
The fact that people write academic papers about it should be good evidence.
C's printf has been hammered on by literally generations of programmers over 3
decades. While the interface to it is old-fashioned and unsafe, the guts of it
are rock solid, fast, and correct.
More information about the Digitalmars-d
mailing list