]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_ceil1.cc
Initial revision
[cln.git] / src / integer / division / cl_I_ceil1.cc
1 // ceiling1().
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 ceiling1 (const cl_I& x, const cl_I& y)
15 {
16 // Methode:
17 // (ceiling x y) :==
18 // (DIVIDE (abs x) (abs y)) -> q,r
19 // Falls x,y selbes Vorzeichen haben und r<>0,
20 //   setze q:=q+1 und r:=r-abs(y).
21 // Falls x<0, setze r:=-r.
22 // Falls x,y verschiedene Vorzeichen haben, setze q:=-q.
23 // Liefere nur q.
24   var cl_I abs_y = abs(y);
25   var cl_I_div_t q_r = cl_divide(abs(x),abs_y);
26   var cl_I& q = q_r.quotient;
27   var cl_I& r = q_r.remainder;
28   if (minusp(x) == minusp(y))
29     { if (!zerop(r)) { q = q + 1; } }
30     else
31     { q = -q; }
32   return q;
33 }