Fix _str_to_int precision loss above 2^53 and add math_eval tests#29
Merged
crazydonkey200 merged 1 commit intoJun 14, 2026
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
`_str_to_int` converted strings via `float(x)` before `int(x)`, which silently lost precision for integers larger than 2^53 (the largest integer a float64 represents exactly). For example '9007199254740993' (2^53 + 1) returned 9007199254740992. Parse integer-formatted strings directly with `int(x)`, which has arbitrary precision, and fall back to `float()` only for non-integer formats like '1.0' or '5e3'. This resolves the existing TODO. Also add simply/utils/math_eval_test.py, the first test coverage for this module: answer extraction, boxed-answer parsing, normalization helpers, eval gating, the >2^53 regression cases, and an end-to-end `match` test that skips when sympy is unavailable. 66 tests, all pass.
6e73c05 to
069ee68
Compare
chenchenpan
added a commit
to chenchenpan/simply-googledeepmind
that referenced
this pull request
Jun 14, 2026
chenchenpan
added a commit
to chenchenpan/simply-googledeepmind
that referenced
this pull request
Jun 14, 2026
chenchenpan
added a commit
to chenchenpan/simply-googledeepmind
that referenced
this pull request
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
math_eval._str_to_intconverted strings tointviafloat(x), whichsilently loses precision for integers larger than 2^53 — the largest integer a
float64 can represent exactly. This resolves the existing
TODOon thatfunction and adds the first test coverage for
math_eval.py.The bug
float('9007199254740993')(2^53 + 1) rounds to9007199254740992.0, so_str_to_intreturned9007199254740992— off by one. Larger values driftfurther (e.g.
'12345678901234567890'->12345678901234567168).This matters for MATH-style answer grading:
_str_to_intfeeds_normalize,so two distinct large integers could normalize to the same string and be graded
as equal.
The fix
Parse integer-formatted strings directly with
int(x)(arbitrary precision),and fall back to
float()only for non-integer formats:'1.0'and'5e3'raiseValueErroronint()and fall through to the floatpath, so existing behavior for those is preserved.
Tests
Adds
simply/utils/math_eval_test.py(absltest+parameterized, matchingthe repo convention) — the first tests for this module. Covers answer
extraction,
\boxed{}/\fbox{}parsing, normalization helpers, eval gating,split_tuple, the>2^53regression cases, and an end-to-endmatchtest(skipped when
sympyis unavailable). 66 tests, all passing.Notes
_str_to_intis module-private.