ModAlt
See Also: Math Functions, Integer
Purpose
ModAlt is an alternate to the Mod (modulo) function. ModAlt returns the remainder from the division of one integer value by another.
Return Type
What It Does
The difference in behavior only applies when {dividend}, the number being divided, is negative. The Mod behavior is standard for most computer languages, which returns the remainder of the division as a negative number. For example, Mod(-1, 5) would return -1.
An alternate mod mechanism is based more on a clock model, where the returned value is a positive number that wraps based on the value of the divisor. For example, ModAlt(-1, 5) would return 4. Mod and ModAlt always behave the same when working with positive numbers.
Here is a comparison of the two functions:
| {dividend} | {divisor} | Mod | ModAlt |
|---|---|---|---|
| 4 | 3 | 1 | 1 |
| 3 | 3 | 0 | 0 |
| 2 | 3 | 2 | 2 |
| 1 | 3 | 1 | 1 |
| 0 | 3 | 0 | 0 |
| -1 | 3 | -1 | 2 |
| -2 | 3 | -2 | 1 |
| -3 | 3 | 0 | 0 |
| -4 | 3 | -1 | 2 |
Syntax
(ModAlt({dividend}, {divisor}))
Where:
{dividend}is the integer value to divide.{divisor}is the integer value to divide{dividend}by.
See Mod for more information.