blob: d0306213b634724fff8c199aba45891d3957d1ee (
plain)
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
83
84
85
86
87
|
---
title: Math.cosh()
slug: Web/JavaScript/Reference/Global_Objects/Math/cosh
tags:
- ECMAScript6
- JavaScript
- Math
- Méthode
- Reference
- polyfill
translation_of: Web/JavaScript/Reference/Global_Objects/Math/cosh
original_slug: Web/JavaScript/Reference/Objets_globaux/Math/cosh
---
{{JSRef}}
La fonction **`Math.cosh()`** renvoie le cosinus hyperbolique d'un nombre, défini par :
<math><semantics><mrow><mstyle mathvariant="monospace"><mo lspace="0em" rspace="thinmathspace">Math.cosh(x)</mo></mstyle><mo>=</mo><mfrac><mrow><msup><mi>e</mi><mi>x</mi></msup><mo>+</mo><msup><mi>e</mi><mrow><mo>-</mo><mi>x</mi></mrow></msup></mrow><mn>2</mn></mfrac></mrow><annotation encoding="TeX">\mathtt{\operatorname{Math.cosh(x)}} = \frac{e^x + e^{-x}}{2}</annotation></semantics></math>
{{EmbedInteractiveExample("pages/js/math-cosh.html")}}
(Voir la page sur {{jsxref("Objets_globaux/Math/E","e","",1)}})
## Syntaxe
Math.cosh(x)
### Paramètres
- `x`
- : Un nombre.
### Valeur de retour
Le cosinus hyperbolique du nombre passé en argument.
## Description
`cosh()` étant une méthode statique de `Math`, il faut utiliser `Math.cosh()` et non pas la méthode d'un objet `Math` créé sur mesure (`Math` n'est pas un constructeur).
## Exemple
### Utiliser `Math.cosh()`
```js
Math.cosh(0); // 1
Math.cosh(1); // 1.5430806348152437
Math.cosh(-1); // 1.5430806348152437
```
## Prothèse d'émulation (_polyfill_)
Cette fonction peut être émulée grâce à la fonction {{jsxref("Objets_globaux/Math/exp", "Math.exp()")}} :
```js
Math.cosh = Math.cosh || function(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
}
```
On peut également utiliser un unique appel à {{jsxref("Objets_globaux/Math/exp", "exp()")}} :
```js
Math.cosh = Math.cosh || function(x) {
var y = Math.exp(x);
return (y + 1 / y) / 2;
}
```
## Spécifications
| Spécification | État | Commentaires |
| ------------------------------------------------------------------------ | ---------------------------- | -------------------- |
| {{SpecName('ES6', '#sec-math.cosh', 'Math.cosh')}} | {{Spec2('ES6')}} | Définition initiale. |
| {{SpecName('ESDraft', '#sec-math.cosh', 'Math.cosh')}} | {{Spec2('ESDraft')}} | |
## Compatibilité des navigateurs
{{Compat("javascript.builtins.Math.cosh")}}
## Voir aussi
- {{jsxref("Math.acosh()")}}
- {{jsxref("Math.asinh()")}}
- {{jsxref("Math.atanh()")}}
- {{jsxref("Math.sinh()")}}
- {{jsxref("Math.tanh()")}}
|