Math node
Math
Universal arithmetic and mathematical function node with 24 operations covering basic arithmetic, trigonometry, rounding, and more. The Math node is the primary building block for numerical computation in Grafit, replacing the need for separate Add, Subtract, Multiply, and other single-purpose math nodes with a single versatile unit.
Inputs
| Port | Type | Default |
|---|---|---|
| AThe first value, and the only one the single-input operations such as Abs, Sin or Floor look at. ALSO accepts an ARRAY (a Loop's collected output, Break Point axes…) — the operation runs element-wise and Result becomes an array. Unsafe cases like the square root of a negative give 0. | float | 0 |
| +Which operation runs — the label becomes the symbol you pick, and single-input operations drop the B port. Values outside the list fall back to addition. | int | 0 |
| BThe second value, ignored by the single-input operations. Also accepts an ARRAY: two arrays pair element-by-element (the shorter clamps to its last value), a plain number broadcasts to every element. Dividing by 0 gives 0 instead of breaking. | float | 0 |
Outputs
| Port | Type |
|---|---|
| Result | float |
Overview
The Math node accepts one or two float inputs and produces a single float result. An operation selector on the node itself lets you pick from 24 operations organized into two groups: ten two-input operations that use both A and B, and fourteen single-input operations that use only A. When a single-input operation is selected, the B port is automatically hidden and any cable connected to it is disconnected. The operation port label on the node dynamically updates to show the symbol of the currently selected operation (for example, +, Abs, Sin), making it easy to identify the node's function at a glance on the graph.
All outputs include NaN and Infinity protection. If the result of any operation is NaN or Inf, the node outputs 0 instead, ensuring downstream nodes always receive a valid number.
Operations
Two-Input Operations (A and B)
These operations require both the A and B inputs. The B port is visible on the node when any of these is selected.
| # | Name | Symbol | Formula | Notes |
|---|---|---|---|---|
| 0 | Add | + | A + B | Basic addition. |
| 1 | Subtract | - | A - B | Basic subtraction. |
| 2 | Multiply | x | A x B | Basic multiplication. |
| 3 | Divide | / | A / B | Division with safety: returns 0 when B is 0. |
| 4 | Modulo | % | A % B | Floating-point remainder (fmod). Returns 0 when B is 0. |
| 5 | Power | Pow | A ^ B | Raises A to the power of B. |
| 6 | Min | Min | min(A, B) | Returns the smaller of A and B. |
| 7 | Max | Max | max(A, B) | Returns the larger of A and B. |
| 8 | Step | Step | A >= B ? 1 : 0 | Returns 1 if A is greater than or equal to B, otherwise 0. Useful for threshold detection. |
| 9 | Atan2 | Atan2 | atan2(A, B) | Two-argument arctangent. Returns the angle in radians between the positive X axis and the point (B, A). Useful for computing direction from coordinates. |
Single-Input Operations (A only)
These operations use only the A input. When selected, the B port is hidden.
| # | Name | Symbol | Formula | Notes | ||
|---|---|---|---|---|---|---|
| 10 | Absolute Value | Abs | \ | A\ | Returns the magnitude of A without regard to sign. | |
| 11 | Negate | Negate | -A | Flips the sign of A. | ||
| 12 | Sign | Sign | sign(A) | Returns 1 if A > 0, -1 if A < 0, or 0 if A is exactly 0. | ||
| 13 | Floor | Floor | floor(A) | Rounds A down to the nearest integer. | ||
| 14 | Ceil | Ceil | ceil(A) | Rounds A up to the nearest integer. | ||
| 15 | Round | Round | round(A) | Rounds A to the nearest integer. | ||
| 16 | Square Root | Sqrt | sqrt(A) | Returns the square root of A. Returns 0 for negative inputs (safe). | ||
| 17 | Fractional Part | Fract | A - floor(A) | Returns only the decimal portion of A. Always in range [0, 1). | ||
| 18 | Sine | Sin | sin(A) | Trigonometric sine. Input A is in radians. | ||
| 19 | Cosine | Cos | cos(A) | Trigonometric cosine. Input A is in radians. | ||
| 20 | Tangent | Tan | tan(A) | Trigonometric tangent. Returns 0 when cos(A) is 0 (pole protection). | ||
| 21 | Natural Log | Log | ln(A) | Natural logarithm (base e). Returns 0 for non-positive inputs. | ||
| 22 | Log Base 2 | Log2 | log2(A) | Logarithm base 2. Returns 0 for non-positive inputs. | ||
| 23 | Exponential | Exp | e^A | Euler's number raised to the power of A. |
Dynamic Behavior
- Operation port renaming: The middle input port dynamically renames itself to display the symbol of the currently selected operation. For example, selecting Multiply changes the port label from
+tox. This rename is reflected in the connection cache so existing cables remain valid. - B port auto-hide: Selecting any single-input operation (Abs through Exp) removes the B port from the node and disconnects any cables that were attached to it. Switching back to a two-input operation restores the B port.
- NaN/Inf protection: Every result is checked before output. If the computation produces NaN or Infinity (for example, dividing 0 by 0, or computing a very large exponent), the output is clamped to 0.
Use Cases
- Basic arithmetic chains: Connect several Math nodes to build addition, multiplication, and scaling pipelines for real-time parameter processing.
- Trigonometric animation: Feed a Time node into the A input with Sin or Cos selected to create smooth oscillating values for animation.
- Threshold gating: Use the Step operation to convert a continuous signal into a binary on/off trigger when it crosses a threshold.
- Angle computation: Use Atan2 to compute the direction angle from X/Y coordinate pairs, for example from mouse position data.
- Signal conditioning: Chain Floor, Ceil, Round, or Fract to quantize or extract portions of incoming data streams.
- Logarithmic scaling: Apply Log or Log2 to compress wide-range sensor data into a perceptually uniform scale.
Practical Tips
- When building complex expressions, consider using the Math Expression node instead of chaining many Math nodes. The Math Expression node lets you type a formula directly.
- The operation selector can be driven by a cable connection. Connect an integer source to the operation port to switch operations dynamically at runtime.
- For division, the node safely returns 0 when dividing by zero rather than producing an error or crash. Keep this in mind when checking for error conditions downstream.
- Trigonometric functions expect input in radians, not degrees. If you have degrees, first multiply by pi/180 using another Math node set to Multiply, or use the Remap node to convert the range.
- The Fract operation is useful for creating repeating patterns. Feed a continuously increasing value (such as elapsed time) into Fract to get a sawtooth wave in the range [0, 1).
Open Math in the interactive catalog →
Math is one of 381 nodes in Grafit Pro.
Free download. Every feature for 7 days, no card. Then €99.99 once — or keep playing your projects as a Player.