Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Math.atan: inverse tangent

Math.atan returns the inverse tangent of a number in radians, ranging from -π/2 to π/2 over the entire real line.

Version: ECMAScript 1 onward; example target: Node.js 24.22.2

Syntax

Math.atan(x)

Math.atan(x) applies ToNumber and computes the principal inverse tangent. Every finite real number maps into the open interval (-π/2, π/2). +Infinity produces approximately +π/2, -Infinity approximately -π/2, and the sign of zero is preserved: atan(-0) is -0.

NaN or a missing argument produces NaN. A numeric string is converted, while a Symbol or BigInt throws TypeError; an object can invoke valueOf or toString. The result is a Number, and the mathematical approximation may be implementation-dependent.

The function is not a constructor and has been standard since ECMAScript 1. Its result is in radians; degrees are radians * 180 / Math.PI. Math.atan(rise / run) works when only a slope is known, but loses quadrant information and behaves poorly with a zero denominator; for two components normally use Math.atan2(y, x).

Examples

const slope = 1;
const angle = Math.atan(slope);
console.log(angle.toFixed(6), (angle * 180 / Math.PI).toFixed(1));
console.log(Math.atan(Infinity).toFixed(6), Math.atan(-Infinity).toFixed(6));
console.log(Object.is(Math.atan(-0), -0));
console.log(Number.isNaN(Math.atan()), Number.isNaN(Math.atan(NaN)));
try { Math.atan(1n); } catch (error) { console.log(error instanceof TypeError); }

Result

0.785398 45.0
1.570796 -1.570796
true
true true
true

Sources