]> www.ginac.de Git - cln.git/blob - src/rational/division/cl_RA_ceil2.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / rational / division / cl_RA_ceil2.cc
1 // ceiling2().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/rational.h"
8
9
10 // Implementation.
11
12 #include "cl_RA.h"
13 #include "cln/integer.h"
14
15 namespace cln {
16
17 const cl_RA_div_t ceiling2 (const cl_RA& x)
18 {
19 // Methode:
20 // x Integer -> (q,r) := (x,0)
21 // x Ratio a/b ->
22 //   (ceiling a b) liefert q und r.
23 //   Liefere q und r/b (mit b>1 und ggT(r,b)=ggT(r+q*b,b)=ggT(a,b)=1).
24         if (integerp(x)) {
25                 DeclareType(cl_I,x);
26                 // (q,r) := (x,0)
27                 return cl_RA_div_t(x,0);
28         } else {
29                 DeclareType(cl_RT,x);
30                 var const cl_I& a = numerator(x);
31                 var const cl_I& b = denominator(x);
32                 var cl_I_div_t q_r = ceiling2(a,b);
33                 var cl_I& q = q_r.quotient;
34                 var cl_I& r = q_r.remainder;
35                 return cl_RA_div_t(q,I_I_to_RT(r,b));
36         }
37 }
38
39 }  // namespace cln