]> www.ginac.de Git - cln.git/blob - src/rational/division/cl_RA_ceil12.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / rational / division / cl_RA_ceil12.cc
1 // ceiling1().
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_I ceiling1 (const cl_RA& x, const cl_RA& y)
18 {
19 // Methode:
20 // x = a/b, y = c/d -> liefere (ceiling (* a d) (* b c)).
21 // x Integer -> dito mit b=1.
22 // y Integer -> dito mit d=1.
23 // x und y Integer -> bekannt.
24         if (integerp(x)) {
25                 DeclareType(cl_I,x);
26                 if (integerp(y)) {
27                         DeclareType(cl_I,y);
28                         return ceiling1(x,y);
29                 } else {
30                         DeclareType(cl_RT,y);
31                         var const cl_I& c = numerator(y);
32                         var const cl_I& d = denominator(y);
33                         return ceiling1(x*d,c);
34                 }
35         } else {
36                 DeclareType(cl_RT,x);
37                 var const cl_I& a = numerator(x);
38                 var const cl_I& b = denominator(x);
39                 if (integerp(y)) {
40                         DeclareType(cl_I,y);
41                         return ceiling1(a,b*y);
42                 } else {
43                         DeclareType(cl_RT,y);
44                         var const cl_I& c = numerator(y);
45                         var const cl_I& d = denominator(y);
46                         return ceiling1(a*d,b*c);
47                 }
48         }
49 }
50
51 }  // namespace cln