{"record":{"id":"a3b9bca73bd5d2a4","repo":"Comfy-Org/ComfyUI","slug":"math-expression-expression-produced-a-non-fini","errorCode":null,"errorMessage":"Math Expression '{expression}' produced a non-finite result: {result}","messagePattern":"Math Expression '(.+?)' produced a non-finite result: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_math.py","lineNumber":113,"sourceCode":"        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()\n","sourceCodeStart":95,"sourceCodeEnd":127,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_math.py#L95-L127","documentation":"Raised by the Math Expression node when the evaluated result converts to a float but that float is inf or NaN. Python float arithmetic silently produces inf on overflow and NaN from operations like inf - inf or 0 * inf, so the node explicitly rejects non-finite values via math.isfinite before emitting them downstream.","triggerScenarios":"Float expressions that overflow to inf, e.g. '1e308 * 10' or '10.0**400', or NaN-producing mixes like '1e308*10 - 1e308*10'; math functions from MATH_FUNCTIONS returning inf/nan (e.g. log(0.0) style results depending on the allowed function set).","commonSituations":"Scaling factors multiplied together until they exceed double range; division that tends to infinity because a denominator input is 0 after implicit float conversion; chained math nodes compounding magnitudes.","solutions":["Clamp the expression result with min/max against a sane range (e.g. 'min(max(expr, -1e30), 1e30)').","Guard denominators: change 'a/b' to 'a/(b if b != 0 else 1)' or use a conditional so division by ~0 cannot produce inf.","Reduce the magnitude of intermediate products by reordering operations (divide before multiplying).","Check the input values feeding 'values' context; an upstream node may already be passing extreme numbers."],"exampleFix":"// before\nexpr = \"x * 1e308 * 10\"      # -> inf, ValueError non-finite\n\n// after\nexpr = \"min(x * 1e308 * 10, 1e300)\"  # stays finite","handlingStrategy":"validation","validationCode":"import math\nfrom simpleeval import simple_eval\nv = simple_eval(expression, names=context)\nif isinstance(v, (int, float)) and not math.isfinite(float(v)):\n    raise UserFacingError('expression yields a non-finite value')","typeGuard":null,"tryCatchPattern":"try:\n    out = math_node.execute(expression)\nexcept ValueError as e:\n    if 'non-finite' in str(e):\n        # clamp or substitute a safe default\n        out = 0.0\n    else:\n        raise","preventionTips":["Guard denominators (b != 0) inside expressions.","Divide before multiplying to keep magnitudes small.","Clamp results with min/max expressions."],"tags":["math","nan","infinity","expression-eval"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}