{"record":{"id":"b25fd244c78b6329","repo":"Comfy-Org/ComfyUI","slug":"math-expression-expression-produced-a-result-t","errorCode":null,"errorMessage":"Math Expression '{expression}' produced a result too large to represent as a float: {result}","messagePattern":"Math Expression '(.+?)' produced a result too large to represent as a float: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_math.py","lineNumber":108,"sourceCode":"        cls, expression: str, values: io.Autogrow.Type\n    ) -> io.NodeOutput:\n        if not expression.strip():\n            raise ValueError(\"Expression cannot be empty.\")\n\n        context: dict = dict(values)\n        context[\"values\"] = list(values.values())\n\n        result = simple_eval(expression, names=context, functions=MATH_FUNCTIONS)\n        # bool check must come first because bool is a subclass of int in Python\n        if not isinstance(result, (int, float)):\n            raise ValueError(\n                f\"Math Expression '{expression}' must evaluate to a numeric result, \"\n                f\"got {type(result).__name__}: {result!r}\"\n            )\n        try:\n            float_result = float(result)\n        except OverflowError:\n            raise ValueError(\n                f\"Math Expression '{expression}' produced a result too large to \"\n                f\"represent as a float: {result}\"\n            ) from None\n        if not math.isfinite(float_result):\n            raise ValueError(\n                f\"Math Expression '{expression}' produced a non-finite result: {result}\"\n            )\n        return io.NodeOutput(float_result, int(result), bool(result))\n\n\nclass MathExtension(ComfyExtension):\n    @override\n    async def get_node_list(self) -> list[type[io.ComfyNode]]:\n        return [MathExpressionNode]\n\n\nasync def comfy_entrypoint() -> MathExtension:\n    return MathExtension()","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_math.py#L90-L126","documentation":"Raised by the Math Expression node when simple_eval returns a numeric value whose magnitude exceeds float range (e.g. a Python int too large for a 64-bit IEEE double). The node must convert the result to float for its FLOAT output, and float(huge_int) raises OverflowError, which is re-raised as ValueError with the offending expression and result.","triggerScenarios":"Evaluating an expression whose exact-integer arithmetic explodes, such as '9**9**9' or ' factorial(30) * 10**400', where simple_eval returns a giant Python int; float(result) then overflows.","commonSituations":"Exponent towers or factorial chains in a math node feeding a slider/float input; mixing big-integer intermediate steps (Python ints are unbounded) with a node contract that requires a finite float.","solutions":["Rewrite the expression to keep intermediate values in float range (e.g. replace 'a**b' with 'math.pow'-style float ops or reduce exponents).","Compute the result in stages and clamp: wrap the final value in an expression like 'min(max(expr, -1e308), 1e308)'.","If the huge value is legitimate, use the INT output path only by splitting the expression so the float conversion is never attempted on the oversized value.","Catch ValueError at the caller if the expression is user-supplied and report it back to the UI."],"exampleFix":"// before\nexpression = \"9**9**9\"\nresult = node.execute(expression)  # ValueError: result too large\n\n// after\nexpression = \"min(9**9**9, 1e300)\"  # clamp inside the expression\nresult = node.execute(expression)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = math_node.execute(expression)\nexcept ValueError as e:\n    if \"too large to represent as a float\" in str(e):\n        raise UserFacingError(f\"Expression overflows float range: {expression}\") from None\n    raise","preventionTips":["Clamp final expressions with min/max against ~1e300.","Avoid exponent towers and factorial chains in integer arithmetic.","Test user-supplied expressions with simple_eval in a sandbox before queueing the graph."],"tags":["math","overflow","expression-eval","float"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}