deno.land / x / simplestatistic@v7.7.1 / src / sign.js

نووسراو ببینە
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
/** * [Sign](https://en.wikipedia.org/wiki/Sign_function) is a function * that extracts the sign of a real number * * @param {number} x input value * @returns {number} sign value either 1, 0 or -1 * @throws {TypeError} if the input argument x is not a number * @private * * @example * sign(2); // => 1 */function sign(x) { if (typeof x === "number") { if (x < 0) { return -1; } else if (x === 0) { return 0; } else { return 1; } } else { throw new TypeError("not a number"); }}
export default sign;
simplestatistic

Version Info

Tagged at
2 years ago