]> www.ginac.de Git - cln.git/blob - src/complex/transcendental/cl_C_tanh.cc
Initial revision
[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 "cl_complex.h"
8
9
10 // Implementation.
11
12 #include "cl_C.h"
13 #include "cl_real.h"
14
15 const cl_N tanh (const cl_N& x)
16 {
17 // Methode:
18 // x reell -> (/ (sinh x) (cosh x))
19 // x = a+bi -> (/ (complex (* (sinh a) (cos b)) (* (cosh a) (sin b)))
20 //                (complex (* (cosh a) (cos b)) (* (sinh a) (sin b))) )
21         if (realp(x)) {
22                 DeclareType(cl_R,x);
23                 var cl_cosh_sinh_t hyp = cl_cosh_sinh(x);
24                 return hyp.sinh / hyp.cosh;
25         } else {
26                 DeclareType(cl_C,x);
27                 // x=a+bi
28                 var const cl_R& a = realpart(x);
29                 var const cl_R& b = imagpart(x);
30                 var cl_cos_sin_t trig_b = cl_cos_sin(b); // cos(b), sin(b) errechnen
31                 var cl_cosh_sinh_t hyp_a = cl_cosh_sinh(a); // cosh(a), sinh(a) errechnen
32                 return
33                         complex_C(hyp_a.sinh * trig_b.cos, // sinh(a)*cos(b)
34                                   hyp_a.cosh * trig_b.sin // cosh(a)*sin(b), nicht Fixnum 0
35                                  )
36                       / complex(hyp_a.cosh * trig_b.cos, // cosh(a)*cos(b)
37                                 hyp_a.sinh * trig_b.sin // sinh(a)*sin(b)
38                                );
39         }
40 }