Skip to content
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

std::chrono::duration<double, ...> precision 0 seems wrong in v8 #2587

Closed
lukester1975 opened this issue Nov 5, 2021 · 2 comments
Closed

Comments

@lukester1975
Copy link
Contributor

Hello

I think this is a regression (judging by #1004 and #1012).

#include <fmt/chrono.h>

int main(int argc, char* argv[])
{
    std::chrono::duration<double, std::nano> a { 46.666667 };

    fmt::print("{}\n", a);
    fmt::print("{:.0}\n", a);
    fmt::print("{:.1}\n", a);
    fmt::print("{:.2}\n", a);

    fmt::print("{:.0%Q}\n", a);

    // Workaround
    fmt::print("{:.0f}{:%q}\n", a.count(), a);    
}

With v8.0.1 (https://godbolt.org/z/jMe7hGW6M):

46.6667ns
50ns
46.7ns
46.67ns
50
47ns

With 7.1.3 (https://godbolt.org/z/1WxxfhKd4) things are saner:

46.6667ns
47ns
46.7ns
46.67ns
47
47ns

If it should work, maybe test/chrono-test.cc needs a 0 dp test?

Thanks

@vitaut
Copy link
Contributor

vitaut commented Nov 5, 2021

Looks like the problem is that

specs.type = precision > 0 ? presentation_type::fixed_lower

incorrectly uses 0 to denote "no precision". A PR to fix this would be welcome.

@lukester1975
Copy link
Contributor Author

Well I don't know enough about the code to know if it's correct, but here's an attempt: #2588

Added a few more tests for rounding and precision 0 and they all pass, though maybe more could be added.

HTH

@vitaut vitaut closed this as completed Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants