MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / luaO_codeparam

Function luaO_codeparam

src/lobject.cpp:72–87  ·  view source on GitHub ↗

** Encodes 'p'% as a floating-point byte, represented as (eeeexxxx). ** The exponent is represented using excess-7. Mimicking IEEE 754, the ** representation normalizes the number when possible, assuming an extra ** 1 before the mantissa (xxxx) and adding one to the exponent (eeee) ** to signal that. So, the real value is (1xxxx) * 2^(eeee - 7 - 1) if ** eeee != 0, and (xxxx) * 2^-7 otherwise (sub

Source from the content-addressed store, hash-verified

70** eeee != 0, and (xxxx) * 2^-7 otherwise (subnormal numbers).
71*/
72lu_byte luaO_codeparam (unsigned int p) {
73 if (p >= (cast(lu_mem, 0x1F) << (0xF - 7 - 1)) * 100u) /* overflow? */
74 return 0xFF; /* return maximum value */
75 else {
76 p = (cast(l_uint32, p) * 128 + 99) / 100; /* round up the division */
77 if (p < 0x10) { /* subnormal number? */
78 /* exponent bits are already zero; nothing else to do */
79 return cast_byte(p);
80 }
81 else { /* p >= 0x10 implies ceil(log2(p + 1)) >= 5 */
82 /* preserve 5 bits in 'p' */
83 unsigned log = luaO_ceillog2(p + 1) - 5u;
84 return cast_byte(((p >> log) - 0x10) | ((log + 1) << 4));
85 }
86 }
87}
88
89
90/*

Callers 1

lua_gcFunction · 0.85

Calls 1

luaO_ceillog2Function · 0.85

Tested by

no test coverage detected