MCPcopy Create free account
hub / github.com/cosdata/cosdata / nearest_power_of_two

Function nearest_power_of_two

src/metadata/mod.rs:45–53  ·  view source on GitHub ↗

Returns power of 2 that's nearest to the number, rounded up

(n: u16)

Source from the content-addressed store, hash-verified

43
44/// Returns power of 2 that's nearest to the number, rounded up
45fn nearest_power_of_two(n: u16) -> Option<u8> {
46 let powers: Vec<u16> = vec![1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024];
47 for (i, p) in powers.iter().enumerate() {
48 if *p >= n {
49 return Some(i as u8);
50 }
51 }
52 None
53}
54
55/// Converts a number from decimal to binary, represented as a vector
56/// of u8

Callers 1

newMethod · 0.85

Calls 1

iterMethod · 0.45

Tested by

no test coverage detected