Can you dig through into the code, see what's going on, and suggest a documentation patch? To get you started, the code for the complex version of atan2 is in

https://svn.r-project.org/R/trunk/src/main/complex.c

z_atan2 is at line 669 (the first argument is a pointer to the result, args 2 [csn] and 3 [ccs] are pointers to the arguments of atan2())

 In generic cases the computation is

        dr = catan(dcsn / dccs);
        if(creal(dccs) < 0) dr += M_PI;
        if(creal(dr) > M_PI) dr -= 2 * M_PI;

where dcsn, dccs are converted versions of the args.

catan() is *either* taken from system libraries or is defined at line 489.

On my system (Ubuntu), 'man 3 catan' gives documentation on the function, and says "The real part of y is chosen in the interval [-pi/2,pi/2]" - but that _could_ be system-dependent.

   cheers
   Ben Bolker

On 5/18/21 10:39 AM, Jorgen Harmse via R-devel wrote:
The current documentation says that atan2(y,x) is the angle between the x-axis and 
the vector from the origin to (x,y), but what does this mean when x & y are 
complex? The function seems to pick theta with Re(theta) between -pi and pi and 
with tan(theta) (approximately) equal to y/x, but that leaves 2 (sometimes 3) 
options, and there must be a set (branch region with 3 real dimensions?) on which 
the function is discontinuous. Please add details.

Even for real inputs, it might help to spell out the behaviour on the negative 
x-axis. It mostly matches the branch-cut rules for the other functions, but 
atan2(0,0)==0 is a unexpected.

I also suggest ‘See Also’ links from trigonometric functions to hyperbolic 
functions and from hyperbolic functions to exponential & logarithmic functions.

Regards,
Jorgen Harmse.



R.version.string

[1] "R version 4.0.4 (2021-02-15)"






        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to