From 8bc08b0e705f64179e2c65922d26022cd56fbf90 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 25 Mar 2026 13:36:10 +0900 Subject: [PATCH] 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 --- comfy_extras/nodes_number_convert.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/comfy_extras/nodes_number_convert.py b/comfy_extras/nodes_number_convert.py index b2822c856..cac7e736d 100644 --- a/comfy_extras/nodes_number_convert.py +++ b/comfy_extras/nodes_number_convert.py @@ -44,8 +44,13 @@ class NumberConvertNode(io.ComfyNode): def execute(cls, value) -> io.NodeOutput: if isinstance(value, bool): float_val = 1.0 if value else 0.0 - elif isinstance(value, (int, float)): + int_val = 1 if value else 0 + elif isinstance(value, int): float_val = float(value) + int_val = value + elif isinstance(value, float): + float_val = value + int_val = int(value) elif isinstance(value, str): text = value.strip() if not text: @@ -56,6 +61,14 @@ class NumberConvertNode(io.ComfyNode): raise ValueError( f"Cannot convert string to number: {value!r}" ) from None + if not math.isfinite(float_val): + raise ValueError( + f"Cannot convert non-finite value to number: {float_val}" + ) + try: + int_val = int(text) + except ValueError: + int_val = int(float_val) else: raise TypeError( f"Unsupported input type: {type(value).__name__}" @@ -66,7 +79,7 @@ class NumberConvertNode(io.ComfyNode): f"Cannot convert non-finite value to number: {float_val}" ) - return io.NodeOutput(float_val, int(float_val)) + return io.NodeOutput(float_val, int_val) class NumberConvertExtension(ComfyExtension):