$ npm install math-sign-x
Shim for Math.sign.
module.exports(x)
⇒ *
⏏math-sign-x
⇒ number
This method returns the sign of a number, indicating whether the number is positive, negative or zero. (ES2019)
Kind: static property of math-sign-x
Returns: number
- A number representing the sign of the given argument. If the argument
is a positive number, negative number, positive zero or negative zero, the function will
return 1, -1, 0 or -0 respectively. Otherwise, NaN is returned.
Param | Type | Description |
---|---|---|
x | * |
A number. |
Example
import mathSign from 'math-sign-x';
console.log(mathSign(3)); // 1
console.log(mathSign(-3)); // -1
console.log(mathSign('-3')); // -1
console.log(mathSign(0)); // 0
console.log(mathSign(-0)); // -0
console.log(mathSign(NaN)); // NaN
console.log(mathSign('foo')); // NaN
console.log(mathSign()); // NaN
© 2010 - cnpmjs.org x YWFE | Home | YWFE