]> www.ginac.de Git - cln.git/blob - tests/timeRAtoLF.cc
71f7deb860c7cd4ba6f17a4bb0853e8cf1cc6555
[cln.git] / tests / timeRAtoLF.cc
1 #include <cln/number.h>
2 #include <cln/io.h>
3 #include <cln/integer.h>
4 #include <cln/lfloat.h>
5 #include <cln/rational.h>
6 #include <cln/float_io.h>
7 #include <cln/random.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <cln/timing.h>
11
12 int main (int argc, char * argv[])
13 {
14         int repetitions = 1;
15         if ((argc >= 3) && !strcmp(argv[1],"-r")) {
16                 repetitions = atoi(argv[2]);
17                 argc -= 2; argv += 2;
18         }
19         if (argc < 4)
20                 exit(1);
21         uintL m1 = atoi(argv[1]);
22         cl_I m2 = cl_I(argv[2]);
23         cl_I M2 = (cl_I)1 << (intDsize*m2);
24         cl_I m3 = cl_I(argv[3]);
25         cl_I M3 = (cl_I)1 << (intDsize*m3);
26         float_format_t M1 = (float_format_t)(m1*intDsize);
27         cl_I u;
28         cl_I v;
29         do { u = random_I(M2); } while (zerop(u));
30         do { v = random_I(M3); } while (zerop(v) || gcd(u,v) > 1);
31         cl_RA y = u / v;
32         cl_F p;
33         { CL_TIMING;
34           for (int rep = repetitions; rep > 0; rep--)
35             { p = cl_float(u,M1)/cl_float(v,M1); }
36         }
37         cout << p << endl;
38         { CL_TIMING;
39           for (int rep = repetitions; rep > 0; rep--)
40             { p = cl_float(y,M1); }
41         }
42         cout << p << endl;
43 }