PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/cln-1.3.2/src/complex/transcendental/cl_C_atanh.cc

#
C++ | 64 lines | 23 code | 10 blank | 31 comment | 2 complexity | 526b323f611d36b367cfa6ba8df10065 MD5 | raw file
Possible License(s): GPL-2.0
  1. // atanh().
  2. // General includes.
  3. #include "base/cl_sysdep.h"
  4. // Specification.
  5. #include "cln/complex.h"
  6. // Implementation.
  7. #include "complex/cl_C.h"
  8. #include "cln/real.h"
  9. namespace cln {
  10. // Methode:
  11. // Wert und Branch Cuts nach der Formel CLTL2, S. 315:
  12. // artanh(z) = (log(1+z)-log(1-z)) / 2
  13. // Sei z=x+iy, Ergebnis u+iv.
  14. // Falls x=0 und y=0: u=0, v=0.
  15. // Falls x=0: u = 0, v = atan(X=1,Y=y).
  16. // Falls y=0:
  17. // x rational -> x in Float umwandeln.
  18. // |x|<1/2: u = atanh(x), v = 0.
  19. // |x|>=1/2: (1+x)/(1-x) errechnen,
  20. // =0 -> Error,
  21. // >0 (also |x|<1) -> u = 1/2 log((1+x)/(1-x)), v = 0.
  22. // <0 (also |x|>1) -> u = 1/2 log(-(1+x)/(1-x)),
  23. // v = (-pi/2 für x>1, pi/2 für x<-1).
  24. // Sonst:
  25. // 1+x und 1-x errechnen.
  26. // x und y in Floats umwandeln.
  27. // |4x| und 1+x^2+y^2 errechnen,
  28. // |4x| < 1+x^2+y^2 -> u = 1/2 atanh(2x/(1+x^2+y^2)),
  29. // |4x| >= 1+x^2+y^2 -> u = 1/4 ln ((1+x^2+y^2)+2x)/((1+x^2+y^2)-2x)
  30. // oder besser (an der Singularität: |x|-1,|y| klein):
  31. // u = 1/4 ln ((1+x)^2+y^2)/((1-x)^2+y^2).
  32. // 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,
  33. // 1 sonst)
  34. // Ergebnis ist reell nur, wenn z reell.
  35. // Real- und Imaginärteil des Ergebnisses sind Floats, außer wenn z reell oder
  36. // rein imaginär ist.
  37. inline const cl_C_R _atanh (const cl_N& z)
  38. {
  39. if (realp(z)) {
  40. DeclareType(cl_R,z);
  41. return atanh(z,0);
  42. } else {
  43. DeclareType(cl_C,z);
  44. return atanh(realpart(z),imagpart(z));
  45. }
  46. }
  47. const cl_N atanh (const cl_N& z)
  48. {
  49. var cl_C_R u_v = _atanh(z);
  50. var cl_R& u = u_v.realpart;
  51. var cl_R& v = u_v.imagpart;
  52. return complex(u,v);
  53. }
  54. } // namespace cln