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

Function luaO_ceillog2

depends/lua/src/lobject.c:65–80  ·  view source on GitHub ↗

** Computes ceil(log2(x)) */

Source from the content-addressed store, hash-verified

63** Computes ceil(log2(x))
64*/
65int luaO_ceillog2 (unsigned int x) {
66 static const lu_byte log_2[256] = { /* log_2[i] = ceil(log2(i - 1)) */
67 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
68 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
69 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
70 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
71 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
72 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
73 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
74 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
75 };
76 int l = 0;
77 x--;
78 while (x >= 256) { l += 8; x >>= 8; }
79 return l + log_2[x];
80}
81
82
83static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,

Callers 2

countintFunction · 0.85
setnodevectorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected