+
+ // Compute -I*log((x+I*y)/sqrt(x^2+y^2))
+ // == -I*log((x+I*y)/sqrt((x+I*y)*(x-I*y)))
+ // Do not "simplify" this to -I/2*log((x+I*y)/(x-I*y))) or likewise.
+ // The branch cuts are easily messed up.
+ const cln::cl_N aux_p = x.to_cl_N()+cln::complex(0,1)*y.to_cl_N();
+ if (cln::zerop(aux_p)) {
+ // x+I*y==0 => y/x==I, so this is a pole (we have x!=0).
+ throw pole_error("atan(): logarithmic pole",0);
+ }
+ const cln::cl_N aux_m = x.to_cl_N()-cln::complex(0,1)*y.to_cl_N();
+ if (cln::zerop(aux_m)) {
+ // x-I*y==0 => y/x==-I, so this is a pole (we have x!=0).
+ throw pole_error("atan(): logarithmic pole",0);
+ }
+ return cln::complex(0,-1)*cln::log(aux_p/cln::sqrt(aux_p*aux_m));