UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ Math/ Math.atan()

The Math.atan() static method returns the inverse tangent (in radians) of a number, that is

π™ΌπšŠπšπš‘.πšŠπšπšŠπš—(𝚑)=arctan(x)=the unique y∊[βˆ’Ο€2,Ο€2] such that tan(y)=x\mathtt{\operatorname{Math.atan}(x)} = \arctan(x) = \text{the unique } y \in \left[-\frac{\pi}{2}, \frac{\pi}{2}\right] \text{ such that } \tan(y) = x

Syntax

Math.atan(x)

Parameters

Return value

The inverse tangent (angle in radians between -Ο€2-\frac{\pi}{2} and Ο€2\frac{\pi}{2}, inclusive) of x. If x is Infinity, it returns Ο€2\frac{\pi}{2}. If x is -Infinity, it returns -Ο€2-\frac{\pi}{2}.

Description

Because atan() is a static method of Math, you always use it as Math.atan(), rather than as a method of a Math object you created (Math is not a constructor).

Examples

Using Math.atan()

Math.atan(-Infinity); // -1.5707963267948966 (-Ο€/2)
Math.atan(-0); // -0
Math.atan(0); // 0
Math.atan(1); // 0.7853981633974483  (Ο€/4)
Math.atan(Infinity); // 1.5707963267948966  (Ο€/2)

// The angle that the line (0,0) -- (x,y) forms with the x-axis in a Cartesian coordinate system
const theta = (x, y) => Math.atan(y / x);

Note that you may want to avoid the theta function and use Math.atan2 instead, which has a wider range (between -Ο€ and Ο€) and avoids outputting NaN for cases such as when x is 0.

Specifications

Browser compatibility

See also