]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_mod.cc
* All Files have been modified for inclusion of namespace cln;
[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 "cln/integer.h"
8
9
10 // Implementation.
11
12 #include "cl_I.h"
13
14 namespace cln {
15
16 const cl_I mod (const cl_I& x, const cl_I& y)
17 {
18 // Methode:
19 // (mod x y) :==
20 // (DIVIDE (abs x) (abs y)) -> q,r
21 // Falls x,y verschiedene Vorzeichen haben und r<>0, setze r:=r-abs(y).
22 // Falls x<0, setze r:=-r.
23 // Liefere r.
24   var cl_I abs_y = abs(y);
25   var cl_I r = cl_divide(abs(x),abs_y).remainder;
26   if (minusp(x) != minusp(y))
27     { if (zerop(r)) { return 0; }
28       r = r - abs_y;
29     }
30   if (minusp(x)) { return -r; } else { return r; }
31 }
32
33 }  // namespace cln