]> www.ginac.de Git - cln.git/blob - src/float/transcendental/cl_LF_atan_recip.cc
Initial revision
[cln.git] / src / float / transcendental / cl_LF_atan_recip.cc
1 // cl_atan_recip().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_F_tran.h"
8
9
10 // Implementation.
11
12 #include "cl_integer.h"
13 #include "cl_lfloat.h"
14 #include "cl_LF.h"
15 #include "cl_LF_tran.h"
16 #include "cl_alloca.h"
17
18 #undef floor
19 #include <math.h>
20 #define floor cln_floor
21
22 // Method:
23 // See examples/atan_recip.cc for a comparison of the algorithms.
24 // Here we take algorithm 2d. It's the fastest throughout the range.
25
26 const cl_LF cl_atan_recip (cl_I m, uintC len)
27 {
28         var uintC actuallen = len + 1;
29         var cl_I m2 = m*m+1;
30         var uintL N = (uintL)(0.69314718*intDsize*actuallen/log(cl_double_approx(m2))) + 1;
31         CL_ALLOCA_STACK;
32         var cl_I* pv = (cl_I*) cl_alloca(N*sizeof(cl_I));
33         var cl_I* qv = (cl_I*) cl_alloca(N*sizeof(cl_I));
34         var uintL n;
35         new (&pv[0]) cl_I (m);
36         new (&qv[0]) cl_I (m2);
37         for (n = 1; n < N; n++) {
38                 new (&pv[n]) cl_I (2*n);
39                 new (&qv[n]) cl_I ((2*n+1)*m2);
40         }
41         var cl_pq_series series;
42         series.pv = pv; series.qv = qv; series.qsv = NULL;
43         var cl_LF result = eval_rational_series(N,series,actuallen);
44         for (n = 0; n < N; n++) {
45                 pv[n].~cl_I();
46                 qv[n].~cl_I();
47         }
48         return shorten(result,len);
49 }
50 // Bit complexity (N = len): O(log(N)^2*M(N)).