]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_ceil1.cc
* */*: Removed problematic stdin, stdout and stderr definitions.
[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 "cln/integer.h"
8
9
10 // Implementation.
11
12 #include "cl_I.h"
13
14 namespace cln {
15
16 const cl_I ceiling1 (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 nur q.
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))
31     { if (!zerop(r)) { q = q + 1; } }
32     else
33     { q = -q; }
34   return q;
35 }
36
37 }  // namespace cln