$ npm install @putout/plugin-math
πPutout plugin helps with Math
.
npm i @putout/plugin-math -D
{
"rules": {
"math/apply-exponentiation": "on",
"math/apply-multiplication": "on",
"math/apply-numeric-separators": "on",
"math/convert-sqrt-to-hypot": "on",
"math/declare": "on"
}
}
The
Math.hypot()
function returns the square root of the sum of squares of its arguments.(c) MDN
Convert Math.sqrt()
to Math.hypot()
. Check out in πPutout Editor.
Math.sqrt(a ** 2, b ** 2);
Math.hypot(a, b);
- The
Math.pow()
static method, given two arguments, base and exponent, returns baseexponent.- The exponentiation operator (
**
) returns the result of raising the first operand to the power of the second operand. It is equivalent toMath.pow
, except it also accepts BigInts as operands.(c) MDN
Math.pow(2, 4);
2 ** 4;
Linter | Rule | Fix |
---|---|---|
π Putout | convert-math-pow |
β |
β£ ESLint | prefer-exponentiation-operator |
β |
Multiplying two numbers stored internally as integers (which is only possible with AsmJS with imul is the only potential circumstance where
Math.imul()
may prove performant in current browsers.(c) MDN
Check out in πPutout Editor.
const a = Math.imul(b, c);
const a = b * c;
To improve readability for numeric literals, underscores (
_
) can be used as separators.(c) MDN
const t = 10000000;
const t = 10_000_000;
The
Math.round()
static method returns the value of a number rounded to the nearest integer.(c) MDN
round(bLength / aLength) > 3;
const {round} = Math;
round(bLength / aLength) > 3;
MIT
© 2010 - cnpmjs.org x YWFE | Home | YWFE