]> www.ginac.de Git - cln.git/blob - src/float/transcendental/cl_LF_coshsinh.cc
87d230ab6dfd70f09ed4d3b09c4b9cce68b254d2
[cln.git] / src / float / transcendental / cl_LF_coshsinh.cc
1 // cl_coshsinh_ratseries().
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_lfloat.h"
13 #include "cl_LF.h"
14 #include "cl_integer.h"
15
16 inline const cl_LF_cosh_sinh_t operator* (const cl_LF_cosh_sinh_t& a, const cl_LF_cosh_sinh_t& b)
17 {
18         return cl_LF_cosh_sinh_t(a.cosh*b.cosh+a.sinh*b.sinh,a.sinh*b.cosh+a.cosh*b.sinh);
19 }
20
21 const cl_LF_cosh_sinh_t cl_coshsinh_ratseries (const cl_LF& x)
22 {
23         // Similar to expx_ratseries.
24         var uintC len = TheLfloat(x)->len;
25         var cl_idecoded_float x_ = integer_decode_float(x);
26         // x = (-1)^sign * 2^exponent * mantissa
27         var uintL lq = cl_I_to_UL(- x_.exponent);
28         var const cl_I& p = x_.mantissa;
29         // Compute sinh(p/2^lq) and cosh(p/2^lq) by splitting into pieces.
30         var cl_boolean first_factor = cl_true;
31         var cl_LF_cosh_sinh_t product;
32         var uintL b1;
33         var uintL b2;
34         for (b1 = 0, b2 = 1; b1 < lq; b1 = b2, b2 = 2*b2) {
35                 // Piece containing bits b1+1..b2 after "decimal point"
36                 // in the binary representation of (p/2^lq).
37                 var uintL lqk = (lq >= b2 ? b2 : lq);
38                 var cl_I pk = ldb(p,cl_byte(lqk-b1,lq-lqk));
39                 // Compute sinh(pk/2^lqk) and cosh(pk/2^lqk).
40                 if (!zerop(pk)) {
41                         if (minusp(x_.sign)) { pk = -pk; }
42                         var cl_LF_cosh_sinh_t factor = cl_coshsinh_aux(pk,lqk,len);
43                         if (first_factor) {
44                                 product = factor;
45                                 first_factor = cl_false;
46                         } else
47                                 product = product * factor;
48                 }
49         }
50         if (first_factor)
51                 return cl_LF_cosh_sinh_t(cl_I_to_LF(1,len),cl_I_to_LF(0,len));
52         else
53                 return product;
54 }
55 // Bit complexity (N = length(x)): O(log(N)^2*M(N)).