4 ms·
Printing Floating-Point Numbers (2014)
- theoh 11y agoSee also Russ Cox's take on this: http://research.swtch.com/ftoa http://research.swtch.com/ftoa
- jhallenworld 11y agoIt 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 11y agoI 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.
- jlarocco 11y ago> 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 11y agoThat 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 11y agoThe 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).
- specialist 11y agoGreat 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-display-floating-point-numbers/ https://www.clarusft.com/dragon4-and-grisu3-algorithms-to-di... "Printing Floating-Point Numbers Quickly and Accurately with Integers" by Florian Loitsch http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/pr... 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