MOD (math/modulus/integer)
The MOD node calculates the modulus (remainder) of dividing two integers. It returns the remainder that results from dividing the first input integer by the second input integer.Inputs
a(integer, default: 0): The dividend, or the number to be divided.b(integer, default: 0): The divisor, or the number to divide by.
Outputs
result(integer): The remainder after dividingabyb.
Configuration
This node has no configuration options.Usage
- Connect an integer value to the
ainput to specify the dividend. - Connect an integer value to the
binput to specify the divisor. - The node will output the remainder of dividing
abybvia theresultoutput.
Example
Let’s say you have a spell that needs to determine if a given number is odd or even. You can use the MOD node to check if the number is divisible by 2.- Connect the integer you want to check to the
ainput of the MOD node. - Connect the integer 2 to the
binput of the MOD node. - If the
resultoutput is 0, the input number is even. If theresultis 1, the input number is odd.
Best Practices
- Make sure to handle the case where
bis 0, as dividing by zero is undefined. You may want to add a check before the MOD node to handle this case gracefully. - Keep in mind that the result of the modulo operation will always have the same sign as the divisor (
b).
Common Issues
- If the
binput is 0, the node will throw an error as division by zero is not allowed. Always ensure thatbis not 0 before using this node. - Be careful when using negative numbers, as the behavior of the modulo operator can be unintuitive. In Magick,
a % balways returns a value with the same sign asb.
