Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Math
  6. atan()

Math.atan()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheMath.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

Try it

// Calculates angle of a right-angle triangle in radiansfunction calcAngle(opposite, adjacent) {  return Math.atan(opposite / adjacent);}console.log(calcAngle(8, 10));// Expected output: 0.6747409422235527console.log(calcAngle(5, 3));// Expected output: 1.0303768265243125

Syntax

js
Math.atan(x)

Parameters

x

A number.

Return value

The inverse tangent (angle in radians between-π2-\frac{\pi}{2} andπ2\frac{\pi}{2}, inclusive) ofx. Ifx isInfinity, it returnsπ2\frac{\pi}{2}. Ifx is-Infinity, it returns-π2-\frac{\pi}{2}.

Description

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

Examples

Using Math.atan()

js
Math.atan(-Infinity); // -1.5707963267948966 (-π/2)Math.atan(-0); // -0Math.atan(0); // 0Math.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 systemconst theta = (x, y) => Math.atan(y / x);

Note that you may want to avoid thetheta function and useMath.atan2() instead, which has a wider range (between -π and π) and avoids outputtingNaN for cases such as whenx is0.

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-math.atan

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp