Skip to content

fix(api): preserve precision for large integers in safe_int#35115

Open
HamzaSwitch wants to merge 1 commit intolanggenius:mainfrom
HamzaSwitch:fix/issue-34405-large-int-precision
Open

fix(api): preserve precision for large integers in safe_int#35115
HamzaSwitch wants to merge 1 commit intolanggenius:mainfrom
HamzaSwitch:fix/issue-34405-large-int-precision

Conversation

@HamzaSwitch
Copy link
Copy Markdown
Contributor

Fixes #34405.

safe_int() was converting through float first via int(float(value)), which silently truncates integers with more than ~15 significant digits because float64 can't represent them exactly. For example: int(float('25227143063332189585438')) yields 25227143063332188061696, losing the last 8 digits. The reporter saw this when passing large integers through code nodes and MCP tool nodes.

Fix: try int(value) first for arbitrary-precision integer conversion. Fall back to int(float(value)) only when int() fails, which still handles float-like strings like "3.14" or "1e10".

Verified: large int 25227143063332189585438 round-trips correctly, normal ints, float strings, None, "null", empty string, and garbage inputs all behave as before. Ruff clean.

safe_int() was converting through float first via int(float(value)),
which silently truncates integers with more than ~15 significant digits
because float64 cannot represent them exactly. For example:
int(float('25227143063332189585438')) yields 25227143063332188061696,
losing the last 8 digits.

Try int(value) first to get arbitrary-precision integer conversion for
integer-like strings. Fall back to int(float(value)) only if int()
fails, which handles float-like strings such as '3.14' or '1e10'.

Fixes langgenius#34405
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When the parameter value is a large integer, it will result in loss of accuracy

1 participant