]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_ceil2.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / integer / division / cl_I_ceil2.cc
1 // ceiling2().
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_div_t ceiling2 (const cl_I& x, const cl_I& y)
17 {
18 // Methode:
19 // (ceiling x y) :==
20 // (DIVIDE (abs x) (abs y)) -> q,r
21 // Falls x,y selbes Vorzeichen haben und r<>0,
22 //   setze q:=q+1 und r:=r-abs(y).
23 // Falls x<0, setze r:=-r.
24 // Falls x,y verschiedene Vorzeichen haben, setze q:=-q.
25 // Liefere q,r.
26   var cl_I abs_y = abs(y);
27   var cl_I_div_t q_r = cl_divide(abs(x),abs_y);
28   var cl_I& q = q_r.quotient;
29   var cl_I& r = q_r.remainder;
30   if ((minusp(x) == minusp(y)) && !zerop(r))
31     { q = q + 1; r = r - abs_y; }
32   if (minusp(x))
33     { r = -r; }
34   if (minusp(x) != minusp(y))
35     { q = -q; }
36   return q_r;
37 }
38
39 }  // namespace cln