** 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
| 60 | ** eeee != 0, and (xxxx) * 2^-7 otherwise (subnormal numbers). |
| 61 | */ |
| 62 | lu_byte luaO_codeparam (unsigned int p) { |
| 63 | if (p >= (cast(lu_mem, 0x1F) << (0xF - 7 - 1)) * 100u) /* overflow? */ |
| 64 | return 0xFF; /* return maximum value */ |
| 65 | else { |
| 66 | p = (cast(l_uint32, p) * 128 + 99) / 100; /* round up the division */ |
| 67 | if (p < 0x10) { /* subnormal number? */ |
| 68 | /* exponent bits are already zero; nothing else to do */ |
| 69 | return cast_byte(p); |
| 70 | } |
| 71 | else { /* p >= 0x10 implies ceil(log2(p + 1)) >= 5 */ |
| 72 | /* preserve 5 bits in 'p' */ |
| 73 | unsigned log = luaO_ceillog2(p + 1) - 5u; |
| 74 | return cast_byte(((p >> log) - 0x10) | ((log + 1) << 4)); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /* |
no test coverage detected