-
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
Use Grisu for FP formatting with precision #1032
Comments
Fixed precision is partly implemented in 8af651b. |
Grisu is now used with fixed precision too ( |
As a nice side effect {fmt} beats printf now, even without any micro-optimizations:
|
Enabled Grisu for general format in 76d326a. Need to do the same for exponential. |
Exponent notation is done too. |
I'm coming from #1244. Unfortunately this is not yet working, or I'm doing something wrong. #include <fmt/format.h>
#include <iostream>
int main() {
std::cout << fmt::format("{:.{}e}", 2.5, 0) << std::endl;
} gives
but using MSVC gives
Tested with f675cb8 (Remove redundant cast, 2019-12-08). |
Fixed form still uses |
@vitaut Thanks, but I'm using |
By fixed I meant any of
Here's where the fallback is called if Grisu gives up: Line 1073 in 598e604
It needs to be replaced with a fixed-precision equivalent of Line 964 in 598e604
It might be a fair amount of work mostly to generalize |
Note that the current behavior is not completely incorrect, it's just that the rounding mode is inconsistent between platforms. |
@vitaut Thanks for the hints! |
{fmt} now uses the correct rounding even on systems with broken fmt::print("{:.0e}", 2.5); Output:
|
@vitaut Thanks for the fix. I've just tested it and it works now for my use case as well. FYI: We are using fmt inside https://docs.byte-physics.de/json-xop. |
Currently Grisu is only used for the default (shortest decimal) formatting without precision. Investigate if it is possible to use it with given precision, at least when precision is relatively small.
The text was updated successfully, but these errors were encountered: