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

Failure scanning negative floating-point decimals #106

Closed
petrmanek opened this issue Mar 26, 2024 · 3 comments
Closed

Failure scanning negative floating-point decimals #106

petrmanek opened this issue Mar 26, 2024 · 3 comments

Comments

@petrmanek
Copy link

petrmanek commented Mar 26, 2024

Hi, I discovered a potentially serious bug in v1.1. The following code does not correctly scan a negative decimal value:

double scanned;
scn::scan("-1.5036", "{}", scanned);
std::printf("%f\n", scanned);
// prints 1.5036 (without minus sign)

The same goes for:

auto scanned = scn::scan_value<double>("-1.5036");
std::printf("%f\n", scanned.value());
// prints 1.5036 (without minus sign)

I tried using the {:f} format string without improvement. Am I doing something wrong? My current hypothesis is that the minus sign is discarded because it is considered not to be a part of the scanned value. I would appreciate a second opinion.

@petrmanek
Copy link
Author

One addendum: I have just tried reproducing this the latest v1 branch and found that this bug is present only with SCN_DISABLE_LOCALE=ON

@petrmanek
Copy link
Author

One more addendum: v2 (the latest master) appears not to produce this bug.

@eliaskosunen
Copy link
Owner

If the issue is really only present in v1 with SCN_DISABLE_LOCALE on, I don't think I'll do anything about it myself: I don't really intend to touch v1 anymore. Your hypothesis is likely correct, as SCN_DISABLE_LOCALE isn't and wasn't really tested properly in v1.

Thanks for the report, anyway!

@eliaskosunen eliaskosunen closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
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