MOD (math/modulus/float)
The MOD node calculates the modulus (remainder) of dividing the first input by the second input. It operates on floating-point numbers.Inputs
a(float, default: 0): The dividend, or the number to be divided.b(float, default: 0): The divisor, or the number to divide by.
Outputs
result(float): The remainder after dividingabyb.
Configuration
This node has no configuration options.Usage
- Connect a node providing the dividend (number to be divided) to the
ainput. - Connect a node providing the divisor (number to divide by) to the
binput. - The
resultoutput will emit the remainder after dividingabyb.
Example
Consider a spell where you want to create a repeating color pattern based on the index of each item in a list. You can use the MOD node to get the remainder when dividing the index by the number of colors, ensuring the color index always stays within the valid range.- The
list/generatenode creates a list of 10 items. - The
list/mapspell runs for each item. - Inside the map spell, the
list/indexnode provides the current item index. - The MOD node calculates the remainder of dividing the index by 3 (the number of colors).
- The
list/getnode uses the remainder as the index to select the color from the["red", "green", "blue"]list. - The map spell outputs the selected color for each item.
Best Practices
- Ensure the divisor (
binput) is not zero, as division by zero is undefined. You may want to add ais/nullcheck or adefault/floatnode to handle this case gracefully. - Keep in mind the MOD node works with floats. If you need integer modulus, round the inputs first or use the
math/modulus/integernode instead.
Common Issues
- If the MOD node receives a null or non-numeric input, it will output null. Handle these cases with type checking, default values, or error handling as needed.
- Remember
