]> www.ginac.de Git - cln.git/blob - src/complex/transcendental/cl_C_tanh.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / complex / transcendental / cl_C_tanh.cc
1 // tanh().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/complex.h"
8
9
10 // Implementation.
11
12 #include "cl_C.h"
13 #include "cln/real.h"
14
15 namespace cln {
16
17 const cl_N tanh (const cl_N& x)
18 {
19 // Methode:
20 // x reell -> (/ (sinh x) (cosh x))
21 // x = a+bi -> (/ (complex (* (sinh a) (cos b)) (* (cosh a) (sin b)))
22 //                (complex (* (cosh a) (cos b)) (* (sinh a) (sin b))) )
23         if (realp(x)) {
24                 DeclareType(cl_R,x);
25                 var cosh_sinh_t hyp = cosh_sinh(x);
26                 return hyp.sinh / hyp.cosh;
27         } else {
28                 DeclareType(cl_C,x);
29                 // x=a+bi
30                 var const cl_R& a = realpart(x);
31                 var const cl_R& b = imagpart(x);
32                 var cos_sin_t trig_b = cos_sin(b); // cos(b), sin(b) errechnen
33                 var cosh_sinh_t hyp_a = cosh_sinh(a); // cosh(a), sinh(a) errechnen
34                 return
35                         complex_C(hyp_a.sinh * trig_b.cos, // sinh(a)*cos(b)
36                                   hyp_a.cosh * trig_b.sin // cosh(a)*sin(b), nicht Fixnum 0
37                                  )
38                       / complex(hyp_a.cosh * trig_b.cos, // cosh(a)*cos(b)
39                                 hyp_a.sinh * trig_b.sin // sinh(a)*sin(b)
40                                );
41         }
42 }
43
44 }  // namespace cln