]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_mod.cc
Initial revision
[cln.git] / src / integer / division / cl_I_mod.cc
1 // mod().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_integer.h"
8
9
10 // Implementation.
11
12 #include "cl_I.h"
13
14 const cl_I mod (const cl_I& x, const cl_I& y)
15 {
16 // Methode:
17 // (mod x y) :==
18 // (DIVIDE (abs x) (abs y)) -> q,r
19 // Falls x,y verschiedene Vorzeichen haben und r<>0, setze r:=r-abs(y).
20 // Falls x<0, setze r:=-r.
21 // Liefere r.
22   var cl_I abs_y = abs(y);
23   var cl_I r = cl_divide(abs(x),abs_y).remainder;
24   if (minusp(x) != minusp(y))
25     { if (zerop(r)) { return 0; }
26       r = r - abs_y;
27     }
28   if (minusp(x)) { return -r; } else { return r; }
29 }