** 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. */
| 39 | ** eeeee != 0 and (xxx) otherwise. |
| 40 | */ |
| 41 | int 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 */ |