MCPcopy Create free account
hub / github.com/DFHack/dfhack / ilog2

Function ilog2

depends/lodepng/lodepng.cpp:5424–5432  ·  view source on GitHub ↗

integer binary logarithm, max return value is 31 */

Source from the content-addressed store, hash-verified

5422
5423/* integer binary logarithm, max return value is 31 */
5424static size_t ilog2(size_t i) {
5425 size_t result = 0;
5426 if(i >= 65536) { result += 16; i >>= 16; }
5427 if(i >= 256) { result += 8; i >>= 8; }
5428 if(i >= 16) { result += 4; i >>= 4; }
5429 if(i >= 4) { result += 2; i >>= 2; }
5430 if(i >= 2) { result += 1; /*i >>= 1;*/ }
5431 return result;
5432}
5433
5434/* integer approximation for i * log2(i), helper function for LFS_ENTROPY */
5435static size_t ilog2i(size_t i) {

Callers 1

ilog2iFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected