πPutout plugin helps with Math
npm install @putout/plugin-math[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-math.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-math "npm"
πPutout plugin helps with Math.
```
npm i @putout/plugin-math -D
- β
apply-exponentiation;
- β
apply-multiplication;
- β
apply-numeric-separators;
- β
convert-sqrt-to-hypot;
- β
declare;
- β
remove-unchanged-zero-declarations;
`json`
{
"rules": {
"math/apply-exponentiation": "on",
"math/apply-multiplication": "on",
"math/apply-numeric-separators": "on",
"math/convert-sqrt-to-hypot": "on",
"math/declare": "on",
"math/remove-unchanged-zero-declarations": "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.
`js`
Math.sqrt(a 2, b 2);
`js`
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 to Math.pow, except it also accepts BigInts as operands.
>
> (c) MDN
`js`
Math.pow(2, 4);
`js`
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.
`js`
const a = Math.imul(b, c);
`js`
const a = b * c;
> To improve readability for numeric literals, underscores (_) can be used as separators.
>
> (c) MDN
`js`
const t = 10000000;
`js`
const t = 10_000_000;
> The Math.round() static method returns the value of a number rounded to the nearest integer.
>
> (c) MDN
`js`
round(bLength / aLength) > 3;
`js`
const {round} = Math;
round(bLength / aLength) > 3;
Checkout in πPutout Editor.
`js`
for (let index = 0; index < n; index++) {
const tokenDelta = 0;
const templateDelta = 0;
for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
const currentTokenIndex = index + templateIndex - tokenDelta;
const currentToken = tokens[currentTokenIndex];
end = currentTokenIndex + tokenDelta;
}
}
`js``
for (let index = 0; index < n; index++) {
for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
const currentTokenIndex = index + templateIndex;
const currentToken = tokens[currentTokenIndex];
end = currentTokenIndex;
}
}
MIT