ComfyUI > Nodes > ComfyUI > Math Expression

ComfyUI Node: Math Expression

Class Name

ComfyMathExpression

Category
logic
Author
ComfyAnonymous (Account age: 763days)
Extension
ComfyUI
Latest Updated
2026-05-13
Github Stars
112.77K

How to Install ComfyUI

Install this extension via the ComfyUI Manager by searching for ComfyUI
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Math Expression Description

Evaluate mathematical expressions with dynamic inputs securely and efficiently using ComfyMathExpression node.

Math Expression:

The ComfyMathExpression node is a powerful tool designed to evaluate mathematical expressions using dynamically-grown numeric inputs. It leverages the simpleeval library to safely compute expressions, ensuring that operations are performed securely and efficiently. This node is particularly beneficial for users who need to perform complex calculations within their workflows, as it supports a wide range of mathematical functions such as addition, subtraction, multiplication, division, and more advanced operations like logarithms and trigonometric functions. By providing a flexible and robust environment for mathematical evaluation, the ComfyMathExpression node enhances the capability of AI artists to integrate dynamic calculations into their creative processes, allowing for more sophisticated and data-driven artistic outputs.

Math Expression Input Parameters:

expression

The expression parameter is a string input that defines the mathematical formula you wish to evaluate. It can include variables, operators, and functions supported by the node, such as +, -, *, /, pow, sqrt, and trigonometric functions like sin, cos, and tan. The default value is a + b, and it supports multiline input for complex expressions. This parameter is crucial as it dictates the calculation to be performed, and any syntax errors or unsupported operations will result in an error.

values

The values parameter is an autogrow input that dynamically accepts multiple numeric values, which can be integers, floats, or booleans. These values are used as variables within the expression, and they are automatically assigned to variable names such as a, b, c, etc. The minimum number of inputs is one, and there is no explicit maximum, allowing for flexibility in the number of variables used in the expression. This parameter is essential for providing the data needed to evaluate the expression accurately.

Math Expression Output Parameters:

FLOAT

The FLOAT output provides the result of the evaluated expression as a floating-point number. This output is important for scenarios where precision is required, such as when dealing with fractional results or when the expression involves division or other operations that yield non-integer results.

INT

The INT output gives the result of the evaluated expression as an integer. This output is useful when the expression is expected to yield whole numbers, or when the integer part of a floating-point result is sufficient for the task at hand.

BOOL

The BOOL output indicates whether the evaluated expression results in a non-zero value, returning True for non-zero results and False for zero. This output is particularly useful for conditional logic or decision-making processes within a workflow, where the truthiness of a result can dictate subsequent actions.

Math Expression Usage Tips:

  • Ensure that your expression is correctly formatted and only includes supported operations and functions to avoid errors.
  • Use the values parameter to dynamically adjust the inputs to your expression, allowing for flexible and adaptable calculations.
  • Take advantage of the FLOAT, INT, and BOOL outputs to handle different types of results, depending on the precision and format required for your task.

Math Expression Common Errors and Solutions:

Expression cannot be empty.

  • Explanation: This error occurs when the expression parameter is left blank.
  • Solution: Ensure that you provide a valid mathematical expression in the expression parameter.

Math Expression '<expression>' must evaluate to a numeric result, got <type>: <result>

  • Explanation: The expression did not evaluate to a numeric result, possibly due to incorrect syntax or unsupported operations.
  • Solution: Check the expression for syntax errors and ensure that all operations and functions used are supported by the node.

Math Expression '<expression>' produced a non-finite result: <result>

  • Explanation: The expression resulted in a non-finite number, such as infinity or NaN, often due to division by zero or other invalid operations.
  • Solution: Review the expression to ensure that it does not include operations that could lead to non-finite results, such as division by zero.

Math Expression Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

Math Expression