
Printing Floating-Point Numbers (2014) - cronjobber
http://www.ryanjuckett.com/programming/printing-floating-point-numbers/
======
specialist
Great links, thanks. I sometimes noodle with a faster printf for Java, mostly
for giggles. I also found these:

Dragon4 and Grisu3: Algoritms to Display Floating Point Numbers

[https://www.clarusft.com/dragon4-and-grisu3-algorithms-to-
di...](https://www.clarusft.com/dragon4-and-grisu3-algorithms-to-display-
floating-point-numbers/)

"Printing Floating-Point Numbers Quickly and Accurately with Integers" by
Florian Loitsch

[http://www.cs.tufts.edu/~nr/cs257/archive/florian-
loitsch/pr...](http://www.cs.tufts.edu/~nr/cs257/archive/florian-
loitsch/printf.pdf)

And its implementation in C

[https://github.com/google/double-
conversion](https://github.com/google/double-conversion)

Here's a Java implementation of Grisu2 algorithm.

[https://github.com/jnordwick/zerog-grisu](https://github.com/jnordwick/zerog-
grisu)

------
theoh
See also Russ Cox's take on this:
[http://research.swtch.com/ftoa](http://research.swtch.com/ftoa)

------
jlarocco
> Personally, I don't use anything with an MIT or BSD style license because
> I'd rather avoid the legal baggage.

Gees, what a troll.

~~~
quacker
That was surprising. Those are some very, very permissive licenses and pretty
widely used, too. Just today I wrote a plugin and stuck an MIT license on it.
The only requirement is basically that you keep the license/copyright with all
copies of the code. Is that really so much baggage?

~~~
ryanjuckett
The issue is that you need to ship the license with binaries as well. When you
work on systems like game consoles, this gets even more annoying because you
can't just add some sidecart text file. You instead need to write up some UI
page to show the licenses or reference some website that you keep online
forever for people to visit. It's not the end of the worls, but a license that
just requires comments in the source code is a bunch simpler to track (no need
to collate them all into some user facing GUI).

------
jhallenworld
It reminds me that it's annoying that there is no "engineering" mode for
printf (to force the exponent to be a multiple of three). There is this
project on github using %.*f:
[https://github.com/dhoerl/EngineeringNotationFormatter](https://github.com/dhoerl/EngineeringNotationFormatter)

~~~
montecarl
I have always wished that printf (or its equivalent in your language) was
somehow extensible. In a language like Python you can kind of get around this
by defining __str__ on an object an using %s to format it, but that doesn't
help implement something like engineering mode.

