This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| 4rpl:commands:mod2 [2021/01/20 15:40] – crosslinked mod and mod2 Karsten75 | 4rpl:commands:mod2 [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ~~NOTOC~~ | ~~NOTOC~~ | ||
| - | < | + | < |
| + | < | ||
| ====== mod2 ====== | ====== mod2 ====== | ||
| Line 6: | Line 7: | ||
| ===== Description ===== | ===== Description ===== | ||
| - | Perform integer division and returns the value (modulo) of the difference. | + | Perform integer division and returns the value (modulo) of the difference. |
| - | Works differently with negative numbers than [[mod]]. | + | Works differently with negative numbers than [[mod]], if the result of the modulo operation is negative, the divisor will be added to the result.\\ |
| - | Performs this calculation | + | Performs this calculation: '' |
| - | result = a % b; if (result | + | |
| + | When using a positive number as divisor, mod2 is useful for ' | ||
| + | For example: -50 mod(360) will normally return -50, but using mod2 it will return 310. | ||
| + | |||
| + | If the divisor is a negative number and the result of the normal modulo operation is too, then the divisor still gets added. \\ | ||
| + | This means -50 mod2(-360) will return -410 rather than -50 | ||
| ===== Examples ===== | ===== Examples ===== | ||
| <code 4rpl> | <code 4rpl> | ||
| - | trace(5 3 mod2) # | + | -50 360 mod2 Trace # prints |
| </ | </ | ||
| + | |||
| + | === See Also === | ||
| + | * [[4rpl: | ||
| + | |||
| < | < | ||