Math.atan2() (Function)

The inverse tangent of the slope of the two arguments.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 3.0
Internet Explorer - 4.0
Netscape - 2.0
Netscape Enterprise Server version - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-Math.atan2(aValue1, aValue2)
Argument list:aValue1Some meaningful numeric value
aValue2Some meaningful numeric value

This function computes the quotient of arg2/arg1 and then returns the arc tangent of the result. It takes into account which quadrant the value falls into according to the signs of the two arguments.

It is provided in several languages other than JavaScript for those situations where very large numbers are involved.

Traditionally, for this function, the Y argument is placed first and the X argument second.

Special boundary conditions that affect the results are:

Argument1Argument2Result
+infinity+infinity+pi/4
+infinity-infinity+3pi/4
+infinitynon zero+pi/2
-infinity+infinity-pi/4
-infinity-infinity-3pi/4
-infinitynon zero-pi/2
0negativepi * sign of Argument1
0positive0
< 0-infinity-pi
< 00-pi/2
> 0-infinity+pi
> 00+pi/2
Any valueNaNNaN
NaNAny valueNaN
non zero+infinity0

The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations math routines and the specific algorithm selected to evaluate this function.

The result of this method is the arc-tangent of the slope of the two arguments. The result is expressed in radians and ranges from -pi to +pi.

See also:Math object, Math.acos(), Math.asin(), Math.atan(), Math.cos(), Math.sin(), Math.tan(), Trigonometric function

Cross-references:

ECMA 262 edition 2 - section - 15.8.2.5

ECMA 262 edition 3 - section - 15.8.2.5