Skip to content

Fix #378: double Parsing Slight Innaccuracies#669

Open
leftibot wants to merge 1 commit intoChaiScript:developfrom
leftibot:fix/issue-378-double-parsing-slight-innaccuracies
Open

Fix #378: double Parsing Slight Innaccuracies#669
leftibot wants to merge 1 commit intoChaiScript:developfrom
leftibot:fix/issue-378-double-parsing-slight-innaccuracies

Conversation

@leftibot
Copy link
Copy Markdown
Contributor

Automated fix by @leftibot.

What changed

Fix #378: Replace hand-rolled number parsing with std::from_chars
The custom parse_num floating-point implementation produced slightly
different results from the C++ compiler's own literal parsing (e.g.
1.1e-4 was off by a few ULPs). Replace it with std::from_chars which
is locale-independent and matches compiler precision exactly. Also
migrate integer parsing in buildInt from std::stoll/stoull to
std::from_chars, fix the JSON number parser to pass the full numeric
string to from_chars instead of splitting mantissa/exponent and using
std::pow, and update parse_string to use from_chars for arithmetic types.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Files

 CMakeLists.txt                                    |  4 ++
 include/chaiscript/chaiscript_defines.hpp         | 47 ++---------------
 include/chaiscript/dispatchkit/bootstrap.hpp      | 14 ++++--
 include/chaiscript/language/chaiscript_parser.hpp | 61 ++++++++++++-----------
 include/chaiscript/utility/json.hpp               | 16 +++---
 unittests/float_literal_test.cpp                  | 52 +++++++++++++++++++
 6 files changed, 110 insertions(+), 84 deletions(-)

Closes #378

Triggered by @lefticus.

…_chars

The custom parse_num floating-point implementation produced slightly
different results from the C++ compiler's own literal parsing (e.g.
1.1e-4 was off by a few ULPs). Replace it with std::from_chars which
is locale-independent and matches compiler precision exactly. Also
migrate integer parsing in buildInt from std::stoll/stoull to
std::from_chars, fix the JSON number parser to pass the full numeric
string to from_chars instead of splitting mantissa/exponent and using
std::pow, and update parse_string to use from_chars for arithmetic types.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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

Successfully merging this pull request may close these issues.

double Parsing Slight Innaccuracies

1 participant