diff options
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.4 2004/07/09 16:01:38 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.5 2004/10/06 18:34:16 roberto Exp $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -31,12 +31,21 @@ const TValue luaO_nilobject = {{NULL}, LUA_TNIL}; | |||
31 | ** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm) | 31 | ** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm) |
32 | */ | 32 | */ |
33 | int luaO_int2fb (unsigned int x) { | 33 | int luaO_int2fb (unsigned int x) { |
34 | int m = 0; /* mantissa */ | 34 | int e = 0; /* expoent */ |
35 | while (x >= (1<<3)) { | 35 | while (x >= 16) { |
36 | x = (x+1) >> 1; | 36 | x = (x+1) >> 1; |
37 | m++; | 37 | e++; |
38 | } | 38 | } |
39 | return (m << 3) | cast(int, x); | 39 | if (x < 8) return x; |
40 | else return ((e+1) << 3) | (cast(int, x) - 8); | ||
41 | } | ||
42 | |||
43 | |||
44 | /* converts back */ | ||
45 | int luaO_fb2int (int x) { | ||
46 | int e = (x >> 3) & 31; | ||
47 | if (e == 0) return x; | ||
48 | else return ((x & 7)+8) << (e - 1); | ||
40 | } | 49 | } |
41 | 50 | ||
42 | 51 | ||