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

Erroneous fixed-precision formatting for long double #3539

Closed
inicula opened this issue Jul 19, 2023 · 4 comments
Closed

Erroneous fixed-precision formatting for long double #3539

inicula opened this issue Jul 19, 2023 · 4 comments

Comments

@inicula
Copy link

inicula commented Jul 19, 2023

Code:

#include <fmt/core.h>
#include <sstream>

int main()
{
        const char *str = "0.000000001";
        std::stringstream ss(str);

        long double x;
        ss >> x;

        fmt::print("{:.1f}\n", x); // 0.000000001
}

Godbolt: https://godbolt.org/z/16TWs8c8M

@vitaut
Copy link
Contributor

vitaut commented Jul 19, 2023

Good catch, this should be 0.0.

@vitaut
Copy link
Contributor

vitaut commented Jul 20, 2023

Fixed in 388bc29. Thanks for reporting!

@vitaut vitaut closed this as completed Jul 20, 2023
@ToppDev
Copy link

ToppDev commented Jan 25, 2024

This does not seemed fixed

#include <fmt/format.h>
#include <format>
#include <iostream>

int main(void) {
  long double val = 0.0000000000000071054273576010018587L;

  fmt::println("fmt: {:13.7f}", val);
  std::cout << std::format("std: {:13.7f}\n\n", val);
}

Output

fmt:     0.0000001
std:     0.0000000

https://compiler-explorer.com/z/57Tbj3rjx

Can you reopen the issue please

@vitaut vitaut reopened this Jan 25, 2024
@vitaut
Copy link
Contributor

vitaut commented Feb 3, 2024

Good catch, thanks @ToppDev. Fixed in 06311ed.

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

3 participants