diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-11-01 12:06:50 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-11-01 12:06:50 -0300 |
| commit | 737ec947d3f33e73e587f7020dba40b1818ac64d (patch) | |
| tree | b34f39f07b9cf9c9b079145140fa5c9651c81e8d /lobject.c | |
| parent | 45d566f67691ccae8fe4e5299f9a77873f6c223c (diff) | |
| download | lua-737ec947d3f33e73e587f7020dba40b1818ac64d.tar.gz lua-737ec947d3f33e73e587f7020dba40b1818ac64d.tar.bz2 lua-737ec947d3f33e73e587f7020dba40b1818ac64d.zip | |
better implementation for `floating-point bytes'
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 | ||
