-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster float format #147
Comments
Thanks for the link, @newnon. I haven't seen this before but I have plans to implement faster floating-point formatting, so it might be worth looking at the methods used in stringencoders too. |
There is also relevant discussion here: #116 |
A custom implementation of floating-point formatting will also allow locale-independent formatting as in Python. |
@vitaut, what will be the fastest way to ramp-up and contribute? |
@NotImplemented Awesome that you interested in contributing! I think for this particular issue we need an implementation of one of the Grisu algorithms described in Printing Floating-Point Numbers Quickly and Accurately with Integers to be used instead of |
@newnon, conversion in stringencoders is not correct. Have you seen lines in modp_dtoa()? if (prec < 0) {
prec = 0;
} else if (prec > 9) {
/* precision of >= 10 can lead to overflow errors */
prec = 9;
} Here is benchmark of several conversion algorithms I have done:
|
@NotImplemented No i haven't look inside may be you are right and grisu2 is the fastest algorithm. Unfortunately i'm not to strong in math. Look on https://github.com/miloyip/dtoa-benchmark may be it possible to take some code from there |
FWIW googles double-conversion library is the fastest according to milo's benchmarks (the "milo" implementation he references is pretty much double-conversion with some special cases removed) and the interface looks like it would ammenable to formatting requirements. https://github.com/google/double-conversion |
We can try to facilitate it. The easiest is to start with %F and %f format specifiers. |
In addition to performance this will allow providing locale-independent formatting (#597). |
This has a |
There is also https://github.com/ulfjack/ryu now |
It seems that floating point formatting is not yet locale-independent. Is that true? Is there any ETA on this being addressed? Or if not, is there a recommended workaround? |
Grisu2 implementation is almost complete, but I'm currently busy with preparing for the ISO C++ meeting in Kona, so no specific ETA. One possible workaround is setting the locale to "C". |
I'm concerned with a library, where the app or user may set it behind my back. Is there anyplace in the fmt code where I can doctor it to force "C" locale? I'm a little new to your code and I'm having trouble pinpointing the exact spot where it's retrieving or relying on the global locale. |
You can force locale for FP formatting just before Line 245 in e37d6a9
I'll be happy to accept a PR that does this (conditionally-compiled). |
More requests for locale-independent floating point formatting: https://twitter.com/lefticus/status/1075515381626753024 |
As noticed by Stephan a while ago, Milo's implementation of Grisu2 has rounding issues: https://www.reddit.com/r/cpp/comments/9fiko6/fmt_version_52_released_with_up_to_5x_speedups/e5xmve6/, particularly on 1.9156918820264798e-56. |
{fmt} now uses Grisu for the default |
@vitaut, what about when you use printf ("%f") formatting? what does it use there? |
So just to confirm -- default "{}" formatting is now locale-independent, but non-default formatting (e.g. anything that tries to control the number of digits) is still locale-dependent? |
Right now
Yes, for platforms with IEEE floating point (pretty much all modern platforms). |
Added {fmt} to dtoa_benchmark and here are some results: http://fmtlib.net/unknown_mac64_clang10.0.html. TL;DR: {fmt} is ~13x faster than iostreams, ~10x faster than |
Have you seen this project? They have fast float to string conversions
https://code.google.com/p/stringencoders/
The text was updated successfully, but these errors were encountered: