File size: 2,784 Bytes
780c9fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
---
title: Math.acos()
short-title: acos()
slug: Web/JavaScript/Reference/Global_Objects/Math/acos
page-type: javascript-static-method
browser-compat: javascript.builtins.Math.acos
sidebar: jsref
---
The **`Math.acos()`** static method returns the inverse cosine (in radians) of a number. That is,
<!-- prettier-ignore-start -->
<math display="block">
<semantics><mrow><mo>β</mo><mi>x</mi><mo>β</mo><mo stretchy="false">[</mo><mrow><mo>β</mo><mn>1</mn></mrow><mo>,</mo><mn>1</mn><mo stretchy="false">]</mo><mo>,</mo><mspace width="0.2777777777777778em"></mspace><mrow><mo lspace="0em" rspace="0.16666666666666666em">πΌπππ.ππππ</mo><mo stretchy="false">(</mo><mi>π‘</mi><mo stretchy="false">)</mo></mrow><mo>=</mo><mo lspace="0em" rspace="0em">arccos</mo><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mtext>the unique </mtext><mi>y</mi><mo>β</mo><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mi>Ο</mi><mo stretchy="false">]</mo><mtext> such that </mtext><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mi>x</mi></mrow><annotation encoding="TeX">\forall x \in [{-1}, 1],\;\mathtt{\operatorname{Math.acos}(x)} = \arccos(x) = \text{the unique } y \in [0, \pi] \text{ such that } \cos(y) = x</annotation></semantics>
</math>
<!-- prettier-ignore-end -->
{{InteractiveExample("JavaScript Demo: Math.acos()")}}
```js interactive-example
// Calculates angle of a right-angle triangle in radians
function calcAngle(adjacent, hypotenuse) {
return Math.acos(adjacent / hypotenuse);
}
console.log(calcAngle(8, 10));
// Expected output: 0.6435011087932843
console.log(calcAngle(5, 3));
// Expected output: NaN
```
## Syntax
```js-nolint
Math.acos(x)
```
### Parameters
- `x`
- : A number between -1 and 1, inclusive, representing the angle's cosine value.
### Return value
The inverse cosine (angle in radians between 0 and Ο, inclusive) of `x`. If `x` is less than -1 or greater than 1, returns {{jsxref("NaN")}}.
## Description
Because `acos()` is a static method of `Math`, you always use it as `Math.acos()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).
## Examples
### Using Math.acos()
```js
Math.acos(-2); // NaN
Math.acos(-1); // 3.141592653589793 (Ο)
Math.acos(0); // 1.5707963267948966 (Ο/2)
Math.acos(0.5); // 1.0471975511965979 (Ο/3)
Math.acos(1); // 0
Math.acos(2); // NaN
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{jsxref("Math.asin()")}}
- {{jsxref("Math.atan()")}}
- {{jsxref("Math.atan2()")}}
- {{jsxref("Math.cos()")}}
- {{jsxref("Math.sin()")}}
- {{jsxref("Math.tan()")}}
- CSS {{cssxref("acos()")}} function
|