MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / tanh

Method tanh

src/org/opensourcephysics/numerics/Complex.java:688–713  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

686 }
687
688 public Complex tanh() {
689 double scalar;
690 double temp1Re, temp1Im;
691 double temp2Re, temp2Im;
692 Complex sinRes, cosRes;
693 // tanh(z) = sinh(z) / cosh(z)
694 scalar = Math.exp(re);
695 temp1Re = scalar*Math.cos(im);
696 temp1Im = scalar*Math.sin(im);
697 scalar = Math.exp(-re);
698 temp2Re = scalar*Math.cos(-im);
699 temp2Im = scalar*Math.sin(-im);
700 temp1Re -= temp2Re;
701 temp1Im -= temp2Im;
702 sinRes = new Complex(0.5*temp1Re, 0.5*temp1Im);
703 scalar = Math.exp(re);
704 temp1Re = scalar*Math.cos(im);
705 temp1Im = scalar*Math.sin(im);
706 scalar = Math.exp(-re);
707 temp2Re = scalar*Math.cos(-im);
708 temp2Im = scalar*Math.sin(-im);
709 temp1Re += temp2Re;
710 temp1Im += temp2Im;
711 cosRes = new Complex(0.5*temp1Re, 0.5*temp1Im);
712 return sinRes.div(cosRes);
713 }
714
715 //------------------------------------------------------------------------
716 // Inverse hyperbolic trigonometric functions

Callers 1

builtInFunctionMethod · 0.80

Calls 4

divMethod · 0.95
expMethod · 0.80
cosMethod · 0.45
sinMethod · 0.45

Tested by

no test coverage detected