-
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
Enabling Grisu conversion generates different output #1033
Comments
Grisu2 with 11 bits of extra precision which is what {fmt} implements gives the shortest output in 99.5% of cases. |
To be clear, I totally understand what's going on here and don't doubt the correctness of the conversion. My point was only if this is the output as designed. I got confused from my observation of the ranges test failing on my machine with Grisu-based conversion active since the commit mentioned above. There are two test cases in |
Yes, this is as designed, but will be improved by the next release. |
Have you considerey Ryu? According to their benchmarks, it's still significantly faster. Also, Microsoft chose Ryu for their implementation of |
Ryu is only moderately faster according to a benchmark made by Stephan Lavavej (70-90% IIRC compared to their highly optimized version of Ryu). This might seem like a lot but note that Milo Yip's version of Grisu is 9x faster than |
Regarding the original question, auto pi = static_cast<float>(M_PI);
auto r1 = atof("3.1415927");
assert(r1 == pi); // fails
auto r2 = atof("3.1415927410125732");
assert(r2 == pi); // succeeds |
const double doublePi = 3.14159265358979;
const float floatPi = doublePi;
fmt::print("{}\n", floatPi);
fmt::print("{}\n", doublePi); prints
|
Commit 355eb6d switched the Grisu conversion algorithm active for shortest roundtrip (default) formatting. Alas, I'm a bit puzzled about the outcome compared to the
snprintf
-based conversion: it delivers different outcomes.Consider this test code:
My observed outcome:
Is this as designed?
The text was updated successfully, but these errors were encountered: