]> www.ginac.de Git - cln.git/blob - src/complex/transcendental/cl_C_atanh.cc
Initial revision
[cln.git] / src / complex / transcendental / cl_C_atanh.cc
1 // atanh().
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 // Methode:
16 // Wert und Branch Cuts nach der Formel CLTL2, S. 315:
17 //   artanh(z) = (log(1+z)-log(1-z)) / 2
18 // Sei z=x+iy, Ergebnis u+iv.
19 // Falls x=0 und y=0: u=0, v=0.
20 // Falls x=0: u = 0, v = atan(X=1,Y=y).
21 // Falls y=0:
22 //   x rational -> x in Float umwandeln.
23 //   |x|<1/2: u = atanh(x), v = 0.
24 //   |x|>=1/2: (1+x)/(1-x) errechnen,
25 //             =0 -> Error,
26 //             >0 (also |x|<1) -> u = 1/2 log((1+x)/(1-x)), v = 0.
27 //             <0 (also |x|>1) -> u = 1/2 log(-(1+x)/(1-x)),
28 //                                v = (-pi/2 für x>1, pi/2 für x<-1).
29 // Sonst:
30 //   1+x und 1-x errechnen.
31 //   x und y in Floats umwandeln.
32 //   |4x| und 1+x^2+y^2 errechnen,
33 //   |4x| < 1+x^2+y^2 -> u = 1/2 atanh(2x/(1+x^2+y^2)),
34 //   |4x| >= 1+x^2+y^2 -> u = 1/4 ln ((1+x^2+y^2)+2x)/((1+x^2+y^2)-2x)
35 //                        oder besser (an der Singularität: |x|-1,|y| klein):
36 //                        u = 1/4 ln ((1+x)^2+y^2)/((1-x)^2+y^2).
37 //   v = 1/2 atan(X=(1-x)(1+x)-y^2,Y=2y) * (-1 falls Y=0.0 und X<0.0 und x>=0.0,
38 //                                          1 sonst)
39 // Ergebnis ist reell nur, wenn z reell.
40 // Real- und Imaginärteil des Ergebnisses sind Floats, außer wenn z reell oder
41 // rein imaginär ist.
42
43 inline const cl_C_R _atanh (const cl_N& z)
44 {
45         if (realp(z)) {
46                 DeclareType(cl_R,z);
47                 return atanh(z,0);
48         } else {
49                 DeclareType(cl_C,z);
50                 return atanh(realpart(z),imagpart(z));
51         }
52 }
53
54 const cl_N atanh (const cl_N& z)
55 {
56         var cl_C_R u_v = _atanh(z);
57         var cl_R& u = u_v.realpart;
58         var cl_R& v = u_v.imagpart;
59         return complex(u,v);
60 }