Revision 58d610e1 doc/integer_division.org
doc/integer_division.org  

33  33  
34  34 
* From Euclidian to C 
35  35  
36 
a mod_C b = (a >= 0 ? a mod_M b :  ((a) mod_M b)) 

37 
(using math def to ensure positiveness of remainder)) 

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) 

40 
(using the def of mod_M above) 

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

41  37  
42  38 
a div_C b = (a  (a mod_C b)) div_M b 
43 


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

45  
39 
= (a mod_M b <> 0 && a <= 0)?((a  a mod_M b + abs(b)) div_M b) :((a  a mod_M b) div_M b) 
Also available in: Unified diff