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

Function luaO_int2fb

depends/lua/src/lobject.c:41–53  ·  view source on GitHub ↗

** converts an integer to a "floating point byte", represented as ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if ** eeeee != 0 and (xxx) otherwise. */

Source from the content-addressed store, hash-verified

39** eeeee != 0 and (xxx) otherwise.
40*/
41int luaO_int2fb (unsigned int x) {
42 int e = 0; /* exponent */
43 if (x < 8) return x;
44 while (x >= (8 << 4)) { /* coarse steps */
45 x = (x + 0xf) >> 4; /* x = ceil(x / 16) */
46 e += 4;
47 }
48 while (x >= (8 << 1)) { /* fine steps */
49 x = (x + 1) >> 1; /* x = ceil(x / 2) */
50 e++;
51 }
52 return ((e+1) << 3) | (cast_int(x) - 8);
53}
54
55
56/* converts back */

Callers 1

constructorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected