# manual-is-power-of-two

Prefer isPowerOfTwo over equivalent unsigned integer tests

Testing `countOnes() === 1` or `value !== 0 && (value & (value - 1)) === 0` manually checks whether an unsigned integer is a power of two.
Instead, you SHOULD call `.isPowerOfTwo()` on the integer.

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

## Reported

```ds title="main.ds"
function powerOfTwo(value: uint32): boolean {
    return value !== 0 && (value & (value - 1)) === 0;
}
```

## Accepted

```ds title="main.ds"
function powerOfTwo(value: uint32): boolean {
    return value.isPowerOfTwo();
}
```

## Prior art

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

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