Commit Graph

2 Commits

Author SHA1 Message Date
dante01yoon
8bc08b0e70 fix(number-convert): preserve int precision for large numbers
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
2026-03-25 13:36:10 +09:00
Dante
a0a64c679f
Add Number Convert node (#13041)
* Add Number Convert node for unified numeric type conversion

Consolidates fragmented IntToFloat/FloatToInt nodes (previously only
available via third-party packs like ComfyMath, FillNodes, etc.) into
a single core node.

- Single input accepting INT, FLOAT, STRING, and BOOL types
- Two outputs: FLOAT and INT
- Conversion: bool→0/1, string→parsed number, float↔int standard cast
- Follows Math Expression node patterns (comfy_api, io.Schema, etc.)

Refs: COM-16925

* Register nodes_number_convert.py in extras_files list

Without this entry in nodes.py, the Number Convert node file
would not be discovered and loaded at startup.

* Add isfinite guard, exception chaining, and unit tests for Number Convert node

- Add math.isfinite() check to prevent int() crash on inf/nan string inputs
- Use 'from None' for cleaner exception chaining on string parse failure
- Add 21 unit tests covering all input types and error paths
2026-03-24 15:38:08 -07:00