From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/objets_globaux/math/sign/index.html | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 files/fr/web/javascript/reference/objets_globaux/math/sign/index.html (limited to 'files/fr/web/javascript/reference/objets_globaux/math/sign/index.html') diff --git a/files/fr/web/javascript/reference/objets_globaux/math/sign/index.html b/files/fr/web/javascript/reference/objets_globaux/math/sign/index.html new file mode 100644 index 0000000000..8a1c941e66 --- /dev/null +++ b/files/fr/web/javascript/reference/objets_globaux/math/sign/index.html @@ -0,0 +1,92 @@ +--- +title: Math.sign() +slug: Web/JavaScript/Reference/Objets_globaux/Math/sign +tags: + - ECMAScript 2015 + - JavaScript + - Math + - Méthode + - Reference + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/Math/sign +--- +
{{JSRef}}
+ +

La fonction Math.sign() renvoie le signe d'un nombre et permet de savoir si un nombre est positif, négatif ou nul.

+ +
{{EmbedInteractiveExample("pages/js/math-sign.html")}}
+ + + +

Syntaxe

+ +
Math.sign(x)
+ +

Paramètres

+ +
+
x
+
Un nombre.
+
+ +

Valeur de retour

+ +

Un nombre qui représente le signe de l'argument. Si l'argument est un nombre positif, négatif, un zéro positif ou un zéro négatif, la fonction renverra respectivement 1, -1, 0, -0. Sinon, ce sera {{jsxref("NaN")}} qui sera renvoyé.

+ +

Description

+ +

sign() étant une méthode statique de Math, il faut utiliser Math.sign() et non pas la méthode d'un autre objet qui aurait été créé (Math n'est pas un constructeur).

+ +

Cette fonction peut renvoyer 5 valeurs : 1, -1, 0, -0, NaN, qui indiquent respectivement que x est un nombre positif, un nombre négatif, zéro, la limite négative de zéro, et n'est pas un nombre pour {{jsxref("NaN")}}.

+ +

L'argument passé à cette fonction sera implicitement converti au type number.

+ +

Exemples

+ +
Math.sign(3)     //  1
+Math.sign(-3)    // -1
+Math.sign("-3")  // -1
+Math.sign(0)     //  0
+Math.sign(-0)    // -0
+Math.sign(NaN)   // NaN
+Math.sign("foo") // NaN
+Math.sign()      // NaN
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES6', '#sec-math.sign', 'Math.sign')}}{{Spec2('ES6')}}Définition initiale.
{{SpecName('ESDraft', '#sec-math.sign', 'Math.sign')}}{{Spec2('ESDraft')}}
+ +

Compatibilité des navigateurs

+ + + +

{{Compat("javascript.builtins.Math.sign")}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf