Hash_Table module

next_power_of_two

procedure · 1 overloadSource

The smallest power of two that is at least x, and 1 for anything below that. Fails an assert when the result would not fit an int.

ExampleOpen in playground ↗
assert(next_power_of_two(33) == 64);
assert(next_power_of_two(64) == 64);
assert(next_power_of_two(0) == 1);
next_power_of_two :: (x: int) -> int

The smallest power of two that is at least x, and 1 for anything below that. Fails an assert when the result would not fit an int.

Parameters

x: int

Returns

int
ExampleOpen in playground ↗
assert(next_power_of_two(33) == 64);
assert(next_power_of_two(64) == 64);
assert(next_power_of_two(0) == 1);

See also