Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 8, 2023
1 parent 30b2d11 commit 9006ded
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/rules/prefer-modern-math-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ Math.LOG2E * Math.log(x)
Math.log(x) / Math.LN2
```

## Prefer `Math.hypot(…)` over

```js
Math.sqrt(a * a + b * b)
```

```js
Math.sqrt(a ** 2 + b ** 2)
```

```js
Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2))
```

*This case requires [`prefer-exponentiation-operator`](https://eslint.org/docs/latest/rules/prefer-exponentiation-operator) rule to fix it first.*

```js
Math.sqrt(x ** 2)
// This case fix to `Math.abs(x)`, since it should be better than `Math.hypot(x)`
```

## Separate rule for `Math.trunc()`

See [`unicorn/prefer-math-trunc`](./prefer-math-trunc.md) rule.

0 comments on commit 9006ded

Please sign in to comment.