Acton
Linting rules

E025: divide-before-multiply

Detects cases where division is evaluated before multiplication.

Metadata

  • Code: E025
  • Rule: divide-before-multiply
  • Status: Preview since v0.0.1
  • Quick fix: sometimes available

What it does

Detects cases where division is evaluated before multiplication.

Why is this bad?

Division done too early may lose precision (especially for integer arithmetic) and can produce unintended results in subsequent multiplication.

Example

fun main(a: int, b: int, c: int): int {
    return a / b * c;
E025: division before multiplication may cause precision loss
}

Use instead:

fun main(a: int, b: int, c: int): int {
    return a * c / b;
}

Behavior notes

The check uses CFG + dataflow:

  • reports direct patterns like (x / y) * z and x * (y / z);
  • tracks locals tainted by division through assignments and warns when such values are later used in multiplication.
Source code

Last updated on

On this page