1 // cl_coshsinh_ratseries().
12 #include "cln/lfloat.h"
14 #include "cln/integer.h"
18 inline const cl_LF_cosh_sinh_t operator* (const cl_LF_cosh_sinh_t& a, const cl_LF_cosh_sinh_t& b)
20 return cl_LF_cosh_sinh_t(a.cosh*b.cosh+a.sinh*b.sinh,a.sinh*b.cosh+a.cosh*b.sinh);
23 const cl_LF_cosh_sinh_t cl_coshsinh_ratseries (const cl_LF& x)
25 // Similar to expx_ratseries.
26 var uintC len = TheLfloat(x)->len;
27 var cl_idecoded_float x_ = integer_decode_float(x);
28 // x = (-1)^sign * 2^exponent * mantissa
29 var uintL lq = cl_I_to_UL(- x_.exponent);
30 var const cl_I& p = x_.mantissa;
31 // Compute sinh(p/2^lq) and cosh(p/2^lq) by splitting into pieces.
32 var cl_boolean first_factor = cl_true;
33 var cl_LF_cosh_sinh_t product;
36 for (b1 = 0, b2 = 1; b1 < lq; b1 = b2, b2 = 2*b2) {
37 // Piece containing bits b1+1..b2 after "decimal point"
38 // in the binary representation of (p/2^lq).
39 var uintL lqk = (lq >= b2 ? b2 : lq);
40 var cl_I pk = ldb(p,cl_byte(lqk-b1,lq-lqk));
41 // Compute sinh(pk/2^lqk) and cosh(pk/2^lqk).
43 if (minusp(x_.sign)) { pk = -pk; }
44 var cl_LF_cosh_sinh_t factor = cl_coshsinh_aux(pk,lqk,len);
47 first_factor = cl_false;
49 product = product * factor;
53 return cl_LF_cosh_sinh_t(cl_I_to_LF(1,len),cl_I_to_LF(0,len));
57 // Bit complexity (N = length(x)): O(log(N)^2*M(N)).