12 #include "cl_integer.h"
13 #include "cl_lfloat.h"
15 #include "cl_LF_tran.h"
16 #include "cl_alloca.h"
20 #define floor cln_floor
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.
26 const cl_LF cl_atan_recip (cl_I m, uintC len)
28 var uintC actuallen = len + 1;
30 var uintL N = (uintL)(0.69314718*intDsize*actuallen/log(cl_double_approx(m2))) + 1;
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));
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);
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++) {
48 return shorten(result,len);
50 // Bit complexity (N = len): O(log(N)^2*M(N)).