]> www.ginac.de Git - cln.git/blob - src/complex/transcendental/cl_C_tan.cc
* Removed internal gmp/ directory and other traces of it like $GMP_INCLUDES.
[cln.git] / src / complex / transcendental / cl_C_tan.cc
1 // tan().
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 tan (const cl_N& x)
16 {
17 // Methode:
18 // x reell -> (/ (sin x) (cos x))
19 // x = a+bi -> (/ (complex (* (sin a) (cosh b)) (* (cos a) (sinh b)))
20 //                (complex (* (cos a) (cosh b)) (- (* (sin a) (sinh b)))) )
21         if (realp(x)) {
22                 DeclareType(cl_R,x);
23                 var cl_cos_sin_t trig = cl_cos_sin(x);
24                 return trig.sin / trig.cos;
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_cosh_sinh_t hyp_b = cl_cosh_sinh(b); // cosh(b), sinh(b) errechnen
31                 var cl_cos_sin_t trig_a = cl_cos_sin(a); // cos(a), sin(a) errechnen
32                 return
33                         complex_C(trig_a.sin * hyp_b.cosh, // sin(a)*cosh(b)
34                                   trig_a.cos * hyp_b.sinh // cos(a)*sinh(b), nicht Fixnum 0
35                                  )
36                       / complex(trig_a.cos * hyp_b.cosh, // cos(a)*cosh(b)
37                                 - (trig_a.sin * hyp_b.sinh) // -sin(a)*sinh(b)
38                                );
39         }
40 }