1 // eval_rational_series().
4 #include "base/cl_sysdep.h"
7 #include "float/transcendental/cl_LF_tran.h"
12 #include "cln/lfloat.h"
13 #include "cln/integer.h"
14 #include "cln/exception.h"
15 #include "float/lfloat/cl_LF.h"
20 // Evaluates S = sum(N1 <= n < N2, a(n)/b(n) * (p(N1)...p(n))/(q(N1)...q(n)))
21 // and returns P = p(N1)...p(N2-1), Q = q(N1)...q(N2-1), B = B(N1)...B(N2-1)
22 // and T = B*Q*S (all integers). On entry N1 < N2.
23 // P will not be computed if a NULL pointer is passed.
25 static void eval_b_series_aux (uintC N1, uintC N2,
26 const cl_b_series& args,
31 throw runtime_exception(); break;
37 *B = args.bv[N1] * args.bv[N1+1];
43 var cl_I b12 = args.bv[N1+1] * args.bv[N1+2];
44 *B = args.bv[N1] * b12;
46 + args.bv[N1] * (args.bv[N1+2]
51 var cl_I b01 = args.bv[N1] * args.bv[N1+1];
52 var cl_I b23 = args.bv[N1+2] * args.bv[N1+3];
54 *T = b23 * (args.bv[N1+1]
56 + b01 * (args.bv[N1+3]
61 var uintC Nm = (N1+N2)/2; // midpoint
64 eval_b_series_aux(N1,Nm,args,&LB,<);
65 // Compute right part.
67 eval_b_series_aux(Nm,N2,args,&RB,&RT);
68 // Put together partial results.
70 // S = LS + RS, so T = RB*LT + LB*RT.
77 const cl_LF eval_rational_series (uintC N, const cl_b_series& args, uintC len)
80 return cl_I_to_LF(0,len);
82 eval_b_series_aux(0,N,args,&B,&T);
83 return cl_I_to_LF(T,len) / cl_I_to_LF(B,len);
85 // Bit complexity (if p(n), q(n), a(n), b(n) have length O(log(n))):