fix(number-convert): preserve int precision for large numbers#13147
fix(number-convert): preserve int precision for large numbers#13147comfyanonymous merged 2 commits intomasterfrom
Conversation
The previous implementation converted all inputs through float before producing the INT output (text -> float -> int). This loses precision for integers beyond 2^53, since IEEE 754 doubles cannot represent them exactly (e.g. "9007199254740993" became 9007199254740992). Fix by: - Attempting direct int(text) for string inputs, falling back to int(float_val) only for decimal/scientific strings - Preserving the original value for native int inputs instead of round-tripping through float - Moving the non-finite check before int conversion to properly reject inf/nan strings with a clear error message
Cover the reported precision loss scenario and related edge cases: - String inputs beyond 2^53 (positive, negative, very large) - Native int inputs beyond 2^53 - Decimal string fallback behavior - Large scientific notation strings (1e18) - Type assertion for FLOAT output of large int strings
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis pull request modifies the number conversion node to independently track integer and float values through distinct parsing paths for each input type (boolean, integer, float, string), rather than deriving the integer output solely from the float result. For string inputs, it attempts direct integer parsing before falling back to conversion from the parsed float. The accompanying test suite additions verify correct precision and conversion behavior for large numeric values, including integers exceeding typical floating-point precision limits and scientific notation edge cases. 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes precision loss in the Number Convert node when converting large integer strings to INT output.
Reported by: comfy — Slack thread
Original PR: #13041
Problem
The
execute()method always routed throughfloatbefore producing the INT output:IEEE 754 double-precision floats can only represent integers exactly up to 2^53. For larger values, this round-trip silently loses precision:
"9007199254740993"900719925474099390071992547409929007199254740993(int)90071992547409939007199254740992Fix
int(text)directly first; fall back toint(float_val)only for decimal/scientific notation stringsinf/nanstrings still produce a clear errorTest plan
All 31 tests pass (was 24, added 7 new precision tests).
New test coverage
test_string_large_int_above_2_53"9007199254740993"test_string_large_negative_int_above_2_53"-9007199254740993"test_string_very_large_intstr(2^63+42)test_string_large_int_float_output_is_floatstr(2^53+1)floattypetest_int_large_above_2_532^53+1(native int)test_int_large_negative_above_2_53-(2^53+1)test_int_very_large2^100Existing regression coverage (all passing)
float, INT output isintManual testing checklist
"9007199254740993"— verify INT output is90071992547409939007199254740993— verify INT output matches3.14— verify INT output is3"inf","nan","", and"abc"inputs🤖 Generated with Claude Code