Modulo
The remainder of dividing one number by another.
Node id math/modulo
The Modulo node outputs the remainder of a / b: 7 modulo 3 is 1. It's
useful for repeating patterns, such as alternating every third element.
Inputs
| Name | Type | Default | Notes |
|---|---|---|---|
| a | number | 0 | |
| b | number | 0 |
Outputs
| Name | Type | Notes |
|---|---|---|
| result | number |
Behaviour
- Sign follows
a. Like JavaScript's%, the result has the sign ofa: -7 modulo 3 is -1, not 2. Addbto a negative result to get a value from 0 tob. - Fractions work. 5.5 modulo 2 is 1.5.
- Invalid math. Modulo 0 gives NaN, with no error. Both inputs default
to 0, so
bhas to be set.
Related nodes
- Divide and Floor: the quotient that goes with the remainder.
- Equals Number: with Modulo, tests whether a number is a multiple of another.