]> www.ginac.de Git - cln.git/blob - src/float/lfloat/elem/cl_LF_RA_mul.cc
bump library version, since CLN doesn't export global object ctors any more.
[cln.git] / src / float / lfloat / elem / cl_LF_RA_mul.cc
1 // cl_LF_RA_mul().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_LF.h"
8
9
10 // Implementation.
11
12 #include "cln/lfloat.h"
13 #include "cl_RA.h"
14
15 namespace cln {
16
17 const cl_R cl_LF_RA_mul (const cl_LF& x, const cl_RA& y)
18 {
19 // Method:
20 // Write y = u/v. Return (x*u)/v.
21         if (integerp(y)) {
22                 DeclareType(cl_I,y);
23                 return cl_LF_I_mul(x,y);
24         } else {
25                 DeclareType(cl_RT,y);
26                 var const cl_I& u = TheRatio(y)->numerator; // u /= 0
27                 var const cl_I& v = TheRatio(y)->denominator; // v /= 0
28                 return cl_LF_I_div(The(cl_LF)(cl_LF_I_mul(x,u)),v);
29         }
30 }
31
32 // Timings on an i486 33 MHz, running Linux, in 0.01 sec.
33 // First timing:  (x*u)/v, using cl_LF_I_mul and cl_LF_I_div
34 // Second timing: x*(u/v), using cl_RA_to_LF and operator*
35 // with x_length = 100.
36 //     num_length    50          70          100         200         500
37 // den_length
38 //
39 //         50     1.59 1.92   1.76 1.92   1.89 1.92   1.90 2.78   1.93 8.07
40 //
41 //         70     1.93 2.26   2.14 2.25   2.25 2.25   2.27 2.78   2.25 8.07
42 //
43 //        100     2.44 2.77   2.65 2.77   2.79 2.80   2.80 2.81   2.80 8.05
44 //
45 //        200     2.46 4.53   2.65 4.54   2.78 4.55   2.79 4.55   2.77 8.05
46 //
47 //        500     2.45 8.38   2.65 8.50   2.76 8.49   2.79 8.52   2.81 8.55
48 //
49 // We see that the first approach is always better than the second, except if
50 //    den_length = x_length && x_length <= num_length <= 2*x_length
51 // when both are equally fast.
52
53 }  // namespace cln