# manual-integer-log

Prefer integerLog2 over equivalent base-two integer logarithms

Subtracting the leading-zero count from an integer width manually computes its base-two logarithm.
Instead, you SHOULD call `integerLog2`, which states the operation directly and preserves exact integer behavior.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function magnitude(value: uint32): uint32 {
    return 31 - value.countLeadingZeros();
}
```

## Accepted

```ds title="main.ds"
function magnitude(value: uint32): uint32 {
    return value.integerLog2();
}
```

## Prior art

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

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