ATAN2(3) BSD Programmer's Manual ATAN2(3)

atan2,atan2f- arc tangent function of two variables

libm

#include <math.h>doubleatan2(double y,double x);floatatan2f(float y,float x);

Theatan2() andatan2f() functions compute the principal value of the arc tangent ofy/x, using the signs of both arguments to determine the qua- drant of the return value.

Theatan2() function, if successful, returns the arc tangent ofy/xin the range [-pi, +pi] radians. If bothxandyare zero, the global vari- ableerrnois set to EDOM. On the VAX:atan2(y,x):=atan(y/x) ifx> 0, sign(y)*(pi -atan(|y/x|)) ifx< 0, 0 if x = y = 0, or sign(y)*pi/2 ifx= 0y.

The functionatan2() defines "if x > 0,"atan2(0,0) = 0 on a VAX despite that previouslyatan2(0,0) may have generated an error message. The rea- sons for assigning a value toatan2(0,0) are these: 1. Programs that test arguments to avoid computingatan2(0,0) must be indifferent to its value. Programs that require it to be invalid are vulnerable to diverse reactions to that invali- dity on diverse computer systems. 2. Theatan2() function is used mostly to convert from rectangu- lar (x,y) to polar (r,theta) coordinates that must satisfy x = r*cos theta and y = r*sin theta. These equations are satisfied when (x=0,y=0) is mapped to (r=0,theta=0) on a VAX. In gen- eral, conversions to polar coordinates should be computed thus: r := hypot(x,y); ... := sqrt(x*x+y*y) theta := atan2(y,x). 3. The foregoing formulas need not be altered to cope in a rea- sonable way with signed zeros and infinities on a machine that conforms to IEEE 754; the versions of hypot(3) andatan2() provided for such a machine are designed to handle all cases. That is whyatan2(±0,-0) = ±pi for instance. In general the formulas above are equivalent to these: r := sqrt(x*x+y*y); if r = 0 then x := copysign(1,x);

acos(3), asin(3), atan(3), cos(3), cosh(3), math(3), sin(3), sinh(3), tan(3), tanh(3)

Theatan2() function conforms to ANSI X3.159-1989 ("ANSI C"). MirOS BSD #10-current May 2, 1991 1

Generated on 2016-04-09 18:24:16 by
`$MirOS: src/scripts/roff2htm,v 1.83 2016/03/26 23:38:28 tg Exp $`

These manual pages and other documentation are copyrighted by their respective writers;
their source is available at our CVSweb,
AnonCVS, and other mirrors. The rest is Copyright © 2002–2016 The MirOS Project, Germany.

This product includes material
provided by **mirabilos**.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.