From cb9e359a51c3249d8f5157db69d43fd413ddeda6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:45:12 +0100 Subject: unslug ca: move --- .../reference/global_objects/math/sign/index.html | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/math/sign/index.html (limited to 'files/ca/web/javascript/reference/global_objects/math/sign') diff --git a/files/ca/web/javascript/reference/global_objects/math/sign/index.html b/files/ca/web/javascript/reference/global_objects/math/sign/index.html new file mode 100644 index 0000000000..520ff27dc4 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/math/sign/index.html @@ -0,0 +1,131 @@ +--- +title: Math.sign() +slug: Web/JavaScript/Referencia/Objectes_globals/Math/sign +translation_of: Web/JavaScript/Reference/Global_Objects/Math/sign +--- +
{{JSRef}}
+ +

La funció Math.sign() retorna el signe d'un nombre, indicant si el nombre donat és positiu, negatiu o zero.

+ +

Sintaxi

+ +
Math.sign(x)
+ +

Paràmetres

+ +
+
x
+
Un nombre.
+
+ +

Descripció

+ +

Com que sign() és un mètode estàtic de Math, sempre s'utilitza com Math.sign() en comptes de com un mètode d'un objecte Math creat (Math no és un constructor).

+ +

Aquesta funció pot retornar 5 valors diferents, 1, -1, 0, -0, NaN, que representen "nombre positiu", "nombre negatiu", "zero positiu", "zero negatiu" i {{jsxref("NaN")}} respectivament.

+ +

L'argument passat a aquesta funció serà convertit al tipus de x implícitament.

+ +

Exemples

+ +

Utilitzar Math.sign()

+ +
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
+
+ +

Polyfill

+ +
Math.sign = Math.sign || function(x) {
+  x = +x; // converteix a un nombre
+  if (x === 0 || isNaN(x)) {
+    return x;
+  }
+  return x > 0 ? 1 : -1;
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-math.sign', 'Math.sign')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("38")}}{{CompatGeckoDesktop("25")}}{{CompatNo}}{{CompatOpera("25")}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("25")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

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