# prefer-multiplication-over-power

Prefer multiplication over squaring with exponentiation

Exponentiation performs a general power operation when an expression is only squared.
Instead, you SHOULD multiply the base by itself when its evaluation may be duplicated.

- Category: performance
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function square(value: float64): float64 {
    return value ** 2;
}
```

## Accepted

```ds title="main.ds"
function square(value: float64): float64 {
    return value * value;
}
```

## Prior art

- [Clippy · suboptimal_flops](https://rust-lang.github.io/rust-clippy/master/index.html#suboptimal_flops)

[language/linter/src/rules/performance/prefer_multiplication_over_power.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/prefer_multiplication_over_power.rs#L8)
