aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lobject.c b/lobject.c
index 4091b9d7..5a9b435e 100644
--- a/lobject.c
+++ b/lobject.c
@@ -50,22 +50,22 @@ int luaO_ceillog2 (unsigned int x) {
50} 50}
51 51
52/* 52/*
53** Encodes 'p'% as a floating-point byte, represented as (eeeeexxx). 53** Encodes 'p'% as a floating-point byte, represented as (eeeexxxx).
54** The exponent is represented using excess-7. Mimicking IEEE 754, the 54** The exponent is represented using excess-7. Mimicking IEEE 754, the
55** representation normalizes the number when possible, assuming an extra 55** representation normalizes the number when possible, assuming an extra
56** 1 before the mantissa (xxx) and adding one to the exponent (eeeeexxx) 56** 1 before the mantissa (xxxx) and adding one to the exponent (eeee)
57** to signal that. So, the real value is (1xxx) * 2^(eeeee - 8) if 57** to signal that. So, the real value is (1xxxx) * 2^(eeee - 7 - 1) if
58** eeeee != 0, and (xxx) * 2^-7 otherwise. 58** eeee != 0, and (xxxx) * 2^-7 otherwise (subnormal numbers).
59*/ 59*/
60unsigned int luaO_codeparam (unsigned int p) { 60unsigned int luaO_codeparam (unsigned int p) {
61 if (p >= (cast(lu_mem, 0xF) << 0xF) / 128 * 100) /* overflow? */ 61 if (p >= (cast(lu_mem, 0x1F) << (0xF - 7 - 1)) * 100u) /* overflow? */
62 return 0xFF; /* return maximum value */ 62 return 0xFF; /* return maximum value */
63 else { 63 else {
64 p = (p * 128u) / 100; 64 p = (cast(l_uint32, p) * 128 + 99) / 100; /* round up the division */
65 if (p <= 0xF) 65 if (p < 0x10) /* subnormal number? */
66 return p; 66 return p; /* exponent bits are already zero; nothing else to do */
67 else { 67 else {
68 int log = luaO_ceillog2(p + 1) - 5; 68 int log = luaO_ceillog2(p + 1) - 5; /* preserve 5 bits */
69 return ((p >> log) - 0x10) | ((log + 1) << 4); 69 return ((p >> log) - 0x10) | ((log + 1) << 4);
70 } 70 }
71 } 71 }