User Tools

Site Tools


4rpl:commands:mod2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
4rpl:commands:mod2 [2021/01/08 16:01] – external edit 127.0.0.14rpl:commands:mod2 [2025/02/14 14:57] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ~~NOTOC~~ ~~NOTOC~~
-<=[[4rpl:start| Index]]+<=[[4rpl:start| Index]] \\ 
 +<=[[4rpl:start#arithmetic| Arithmetic]]
  
 ====== mod2 ====== ====== mod2 ======
Line 6: Line 7:
  
 ===== Description ===== ===== Description =====
-Perform integer division and returns the value (modulo) of the difference. Works differently with negative numbers than mod. +Perform integer division and returns the value (modulo) of the difference. \\ 
-Performs this calculation +Works differently with negative numbers than [[mod]], if the result of the modulo operation is negative, the divisor will be added to the result.\\ 
-result = a % b; if (result 0) result += b;+Performs this calculation: ''result = a % b; if (result 0) result += b;'' \\ 
 + 
 +When using a positive number as divisor, mod2 is useful for 'wrapping' a value between 0 and the divisor.\\ 
 +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#prints '2'+-50 360 mod2 Trace # prints 310
 </code> </code>
 +
 +=== See Also ===
 +  * [[4rpl:commands:mod]]
 +
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/mod2.1610121708.txt.gz · Last modified: 2025/02/14 14:56 (external edit)