]> www.ginac.de Git - cln.git/blob - src/real/division/cl_R_ftrunc2.cc
0101ba241fb2838f82fdc9d35c5bd2a7f7cc8d12
[cln.git] / src / real / division / cl_R_ftrunc2.cc
1 // ftruncate2().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_real.h"
8
9
10 // Implementation.
11
12 #include "cl_R.h"
13 #include "cl_R_div_t.h"
14
15 #if 0 // 2 type dispatches
16
17 #include "cl_rational.h"
18 #include "cl_float.h"
19 #include "cl_R_div_t.h"
20
21 const cl_R_fdiv_t ftruncate2 (const cl_R& x)
22 {
23         if (rationalp(x)) {
24                 DeclareType(cl_RA,x);
25                 var cl_RA_div_t q_r = truncate2(x);
26                 var cl_I& q = q_r.quotient;
27                 var cl_RA& r = q_r.remainder;
28                 return cl_R_fdiv_t(cl_float(q),r);
29         } else {
30                 DeclareType(cl_F,x);
31                 return ftruncate2(x);
32         }
33 }
34
35 #else // 1 type dispatch
36
37 #include "cl_RA.h"
38 #include "cl_integer.h"
39 #include "cl_sfloat.h"
40 #include "cl_ffloat.h"
41 #include "cl_dfloat.h"
42 #include "cl_lfloat.h"
43 #include "cl_LF.h"
44
45 const cl_R_fdiv_t ftruncate2 (const cl_R& x)
46 {
47         realcase6(x
48         ,       return cl_R_fdiv_t(cl_float(x),0);
49         ,       var const cl_I& a = numerator(x);
50                 var const cl_I& b = denominator(x);
51                 var cl_I_div_t q_r = truncate2(a,b);
52                 var cl_I& q = q_r.quotient;
53                 var cl_I& r = q_r.remainder;
54                 return cl_R_fdiv_t(cl_float(q),I_I_to_RT(r,b));
55         ,       var cl_SF q = ftruncate(x); return cl_R_fdiv_t(q,x-q);
56         ,       var cl_FF q = ftruncate(x); return cl_R_fdiv_t(q,x-q);
57         ,       var cl_DF q = ftruncate(x); return cl_R_fdiv_t(q,x-q);
58         ,       var cl_LF q = ftruncate(x); return cl_R_fdiv_t(q,LF_LF_minus_LF(x,q));
59         );
60 }
61
62 #endif