Revision 8cc55e2c doc/integer_division.org
doc/integer_division.org  

26  26  
27  27 
* From C to Euclidian 
28  28  
29 
a mod_M b = (a mod_C b) + (a < 0 ? abs(b) : 0) 

29 
a mod_M b = (a mod_C b) + (a mod_C b < 0 ? abs(b) : 0)


30  30  
31  31 
a div_M b = (a  (a mod_M b)) div_C b 
32 
= (a  ((a mod_C b) + (a < 0 ? abs(b) : 0))) div_C b 

32 
= (a  ((a mod_C b) + (a mod_C b < 0 ? abs(b) : 0))) div_C b


33  33  
34  34 
* From Euclidian to C 
35  35  
36  36 
a mod_C b = (a >= 0 ? a mod_M b :  ((a) mod_M b)) 
37  37 
(using math def to ensure positiveness of remainder)) 
38 
= (a mod_M b)  (a < 0 ? abs(b) : 0) 

38 
= (a mod_M b)  (a mod_C < 0 ? abs(b) : 0) 

39 
= a mod_M b  ((a mod_M b <> 0 && a <= 0) ? abs(b) : 0) 

39  40 
(using the def of mod_M above) 
40  41  
41  42 
a div_C b = (a  (a mod_C b)) div_M b 
42 
= (a  ((a mod_M b)  (a < 0 ? abs(b) : 0))) div_M b 

43  43 

44 
Let's chosse the second, simpler, def of mod_C


44 
Let's choose the second, simpler, def of mod_C


45  45 
Also available in: Unified diff