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
parsing of doubles depends on locale #1566
Comments
I tried reproducing, and couldn't make the test fail. Is it just the |
Maybe you don't have the Here is a fork with the extra line: and a simple travis build showing the failing test: |
lkeegan
added a commit
to lkeegan/symengine
that referenced
this issue
Nov 24, 2023
- use `std::from_chars` instead of `strtod` ro parse doubles if available (c++17 required) - otherwise falls back to previous `strtod` implementation - `std::from_chars` is locale independent and faster than `strtod` - add more double parsing tests - add double parsing google benchmarks - resolves symengine#1566
lkeegan
added a commit
to lkeegan/symengine
that referenced
this issue
Nov 24, 2023
- use `std::from_chars` instead of `strtod` ro parse doubles if available (c++17 required) - otherwise falls back to previous `strtod` implementation - `std::from_chars` is locale independent and faster than `strtod` - add more double parsing tests - add double parsing google benchmarks - resolves symengine#1566
lkeegan
added a commit
to lkeegan/symengine
that referenced
this issue
Nov 24, 2023
- use `std::from_chars` instead of `strtod` to parse doubles if available (c++17 required) - otherwise falls back to previous `strtod` implementation - `std::from_chars` is locale independent and faster than `strtod` - add more double parsing tests - add double parsing google benchmarks - resolves symengine#1566
lkeegan
added a commit
to lkeegan/symengine
that referenced
this issue
Feb 20, 2024
- use `std::from_chars` instead of `strtod` to parse doubles if available (c++17 required) - otherwise falls back to previous `strtod` implementation - `std::from_chars` is locale independent and faster than `strtod` - add more double parsing tests - add double parsing google benchmarks - resolves symengine#1566
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
issue
The parser assumes that a double has a
'.'
as the decimal separator:symengine/symengine/parser/parser.ih
Line 100 in f7e253f
and if it finds one, it uses
strtod
to convert the string into a double.This works fine, unless the locale has been set to one where a
','
is used as the separator instead, thenstrtod
will incorrectly convert e.g.3.142
to3
, since it uses the locale defined decimal separator:to reproduce
add the line
to
symengine/symengine/tests/basic/test_parser.cpp
Line 586 in f7e253f
and the "Parsing: doubles" test will fail.
solution
One solution might be to set the locale to the default 'C' one within the parser:
Alternatively just adding a warning that the locale should not be set to something other than the default one somewhere in the docs/wiki would be nice to avoid other users from stumbling across this problem.
Thanks for a great library!
The text was updated successfully, but these errors were encountered: