summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-28 09:08:45 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-28 10:49:46 +0100
commitf37df0022d609443c5b3f222a85ee465d8211b88 (patch)
tree3113ab9212d9d5c0e97bca396c7daf0b4395489c /src/lobject.js
parent8285c78283f922e5b5569ce5c28fb25074db0af3 (diff)
downloadfengari-f37df0022d609443c5b3f222a85ee465d8211b88.tar.gz
fengari-f37df0022d609443c5b3f222a85ee465d8211b88.tar.bz2
fengari-f37df0022d609443c5b3f222a85ee465d8211b88.zip
grammar
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/lobject.js b/src/lobject.js
index f6c6ef0..4974373 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -346,12 +346,32 @@ const luaO_str2num = function(s) {
}
};
+/*
+** 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.
+*/
+int luaO_int2fb (unsigned int x) {
+ int e = 0; /* exponent */
+ if (x < 8) return x;
+ while (x >= (8 << 4)) { /* coarse steps */
+ x = (x + 0xf) >> 4; /* x = ceil(x / 16) */
+ e += 4;
+ }
+ while (x >= (8 << 1)) { /* fine steps */
+ x = (x + 1) >> 1; /* x = ceil(x / 2) */
+ e++;
+ }
+ return ((e+1) << 3) | (x - 8);
+}
+
module.exports.CClosure = CClosure;
module.exports.LClosure = LClosure;
-module.exports.TValue = TValue;
-module.exports.Table = Table;
-module.exports.UTF8BUFFSZ = UTF8BUFFSZ;
module.exports.luaO_chunkid = luaO_chunkid;
module.exports.luaO_hexavalue = luaO_hexavalue;
+module.exports.luaO_int2fb = luaO_int2fb;
module.exports.luaO_str2num = luaO_str2num;
-module.exports.luaO_utf8desc = luaO_utf8desc; \ No newline at end of file
+module.exports.luaO_utf8desc = luaO_utf8desc;
+module.exports.Table = Table;
+module.exports.TValue = TValue;
+module.exports.UTF8BUFFSZ = UTF8BUFFSZ; \ No newline at end of file