Skip to main content

nearest_po2

Function nearest_po2 

pub fn nearest_po2(value: i64) -> i64
Expand description

Returns the smallest integer power of 2 that is greater than or equal to value.

nearest_po2(3) # Returns 4
nearest_po2(4) # Returns 4
nearest_po2(5) # Returns 8

nearest_po2(0)  # Returns 0 (this may not be expected)
nearest_po2(-1) # Returns 0 (this may not be expected)

Warning: Due to its implementation, this method returns 0 rather than 1 for values less than or equal to 0, with an exception for value being the smallest negative 64-bit integer (-9223372036854775808) in which case the value is returned unchanged.