]> www.ginac.de Git - cln.git/blob - src/rational/division/cl_RA_round12.cc
c57078ca54e713efec71c96bdfe11598dc8aca77
[cln.git] / src / rational / division / cl_RA_round12.cc
1 // round1().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_rational.h"
8
9
10 // Implementation.
11
12 #include "cl_RA.h"
13 #include "cl_integer.h"
14
15 const cl_I round1 (const cl_RA& x, const cl_RA& y)
16 {
17 // Methode:
18 // x = a/b, y = c/d -> liefere (round (* a d) (* b c)).
19 // x Integer -> dito mit b=1.
20 // y Integer -> dito mit d=1.
21 // x und y Integer -> bekannt.
22         if (integerp(x)) {
23                 DeclareType(cl_I,x);
24                 if (integerp(y)) {
25                         DeclareType(cl_I,y);
26                         return round1(x,y);
27                 } else {
28                         DeclareType(cl_RT,y);
29                         var const cl_I& c = numerator(y);
30                         var const cl_I& d = denominator(y);
31                         return round1(x*d,c);
32                 }
33         } else {
34                 DeclareType(cl_RT,x);
35                 var const cl_I& a = numerator(x);
36                 var const cl_I& b = denominator(x);
37                 if (integerp(y)) {
38                         DeclareType(cl_I,y);
39                         return round1(a,b*y);
40                 } else {
41                         DeclareType(cl_RT,y);
42                         var const cl_I& c = numerator(y);
43                         var const cl_I& d = denominator(y);
44                         return round1(a*d,b*c);
45                 }
46         }
47 }