Skip to main content

Modulo

This node calculates the remainder of a division operation.

The Modulo node performs the modulo operation (%).

The Modulo node returns the remainder left over when First Number is divided by Second Number. It is essential for cyclic behaviors, checking for even/odd numbers, and wrapping values.

Inputs

Numbers

DataDescription
First NumberThe dividend (the number being divided). Default: 0.
Second NumberThe divisor (the number to divide by). Default: 0. Cannot be 0.

Actions

SignalDescription
DoTriggers the calculation. The result is updated only when this signal is received.

Outputs

Data

DataDescription
ResultThe remainder of the division (First % Second).

Signals

SignalDescription
DoneTriggered when the calculation is successfully completed.

Usage

Example Use Cases

  1. Even/Odd Check: Number % 2. If result is 0, it's even. If 1, it's odd.
  2. Cyclic Index: Looping through an array repeatedly.
    • Current Step % Array Length = Valid Index (0 to Length-1).
  3. Time: Getting seconds from total milliseconds.
    • Total Milliseconds % 1000 = Remaining milliseconds.
  4. Pattern Generation: Creating repeating patterns (e.g., every 3rd item does something different).

Detailed Behavior

  1. Division by Zero:
    • If Second Number is 0, the node logs "Modulo by zero is not allowed" and aborts.
  2. Validation:
    • Inputs must be valid numbers within ±1,000,000,000,000.
  3. Calculation:
    • Uses the JS % operator.
    • Note: In JS, the sign of the result matches the dividend (First Number). -5 % 2 is -1.

Troubleshooting

  • Negative Results: If First Number is negative, the result will be negative. If you need a positive modulo (canonical modulus), you may need additional logic (((a % n) + n) % n).