Skip to content

useModernMathApis (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useModernMathApis": "error"
}
}
}
}

Use modern Math APIs for common mathematical operations.

Dedicated Math methods express mathematical intent directly and avoid reimplementing standard operations. This rule recognizes logarithm conversions, sums of squares, and square roots of squared values.

Math.log(x) * Math.LOG10E;
code-block.js:1:1 lint/nursery/useModernMathApis  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This expression manually converts a natural logarithm.

> 1 │ Math.log(x) * Math.LOG10E;
^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

The dedicated Math API expresses the operation directly.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use Math.log10() instead.

1 - Math.log(x)·*·Math.LOG10E;
1+ Math.log10(x);
2 2

Math.sqrt(a * a + b * b);
code-block.js:1:1 lint/nursery/useModernMathApis  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This expression manually computes the square root of a sum of squares.

> 1 │ Math.sqrt(a * a + b * b);
^^^^^^^^^^^^^^^^^^^^^^^^
2 │

The dedicated Math API expresses the operation directly.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use Math.hypot() instead.

1 - Math.sqrt(a·*·a·+·b·*·b);
1+ Math.hypot(a·,·b);
2 2

Math.sqrt(x ** 2);
code-block.js:1:1 lint/nursery/useModernMathApis  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This expression manually computes an absolute value.

> 1 │ Math.sqrt(x ** 2);
^^^^^^^^^^^^^^^^^
2 │

The dedicated Math API expresses the operation directly.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use Math.abs() instead.

1 - Math.sqrt(x·**·2);
1+ Math.abs(x);
2 2

Math.log10(x);
Math.hypot(a, b);
Math.abs(x);