LogZp1oZm1
From aemwiki
Revision as of 10:47, 5 December 2007 by Analytophile (talk | contribs)
- Language
- c++
- Purpose
- Calculates <math>\ln\left(\frac{Z-1}{Z+1}\right)</math>
- Author
- James R. Craig
#include <math.h> #include <complex> typedef complex<double> cmplex; const double PI=3.141592653589793238462643; // pi /******************************************************************************* logZm1oZp1 optimized version of log ((Z-1.0)/(Z+1.0)): 1.1% of the cost of a direct call- 2 orders of magnitude speedup! Author: James R. Craig -------------------------------------------------------------------------------*/ inline cmplex logZm1oZp1(const cmplex &Z) { double den(Z.real()*Z.real()+Z.imag()*Z.imag()+Z.real()+Z.real()+1.0); double add=0.0; if ((Z.real()*Z.real()+Z.imag()*Z.imag())<1.0){ add=-PI; if (Z.imag()>0.0){add=PI;} } return cmplex(0.5*log(1.0-((Z.real()*(den-Z.real()-2)+den-Z.imag()*Z.imag()-1.0)/(0.25*den*den))), add+atan( (Z.imag()+Z.imag()) /(den-Z.real()-Z.real()-2.0) )); }