JS: Math. sign, abs
Math.sign(x)-
Return
1if x is positive.-1if negative.0if positive 0.-0if negative 0.
(JavaScript's 0 is signed.) see JS: Object.is (test equality)
console.log(Math.sign(3)); // 1 console.log(Math.sign(-3)); // -1 console.log(Math.sign(0)); // 0 console.log(Math.sign(-0)); // -0 Math.abs(x)-
Absolute value.
console.log(Math.abs(-3)); // 3 console.log(Math.abs(0)); // 0 console.log(Math.abs(-0)); // 0
JavaScript. math functions.
- JS: Math (namespace)
- JS: Math. max, min
- JS: Math. sign, abs
- JS: Math ceiling, floor, round, truncate
- JS: Math. random
- JS: Power and Roots
- JS: Math exponential and logarithm
- JS: Math constants. pi, e, sqrt, etc.
- JS: Math trig functions. sin, cos, tan, asin, acos, atan
- JS: Math hyperbolic functions. sinh, cosh, tanh, etc.
- JS: Math fround, clz32, imul