From cad0eac50b70a280611dd89440a805912ebfad8b Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 16 Jun 2017 11:00:16 +0200 Subject: packnum: num can be 32 bits --- src/lstrlib.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lstrlib.js b/src/lstrlib.js index f2518e0..9344794 100644 --- a/src/lstrlib.js +++ b/src/lstrlib.js @@ -548,9 +548,10 @@ const packint = function(b, n, islittle, size, neg) { const packnum = function(b, n, islittle, size) { let dv = new DataView(new ArrayBuffer(size)); - dv.setFloat64(0, n, islittle); + if (size === 4) dv.setFloat32(0, n, islittle); + else dv.setFloat64(0, n, islittle); - for (let i = 0; i < 8; i++) + for (let i = 0; i < size; i++) b.push(dv.getUint8(i, islittle)); }; -- cgit v1.2.3-70-g09d2