From 24467d76fd3d27ca4bc7e03893b2330c22b8ff34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E8=87=B3=E4=BC=9F?= <2473633698@qq.com> Date: Tue, 22 Nov 2016 23:38:59 +0800 Subject: [PATCH] fix a problem of precision loss. the previous code on reading floating point number will cause a precision loss on centimeters, found it when using. --- stream.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/stream.js b/stream.js index 9666ddf..4de763c 100644 --- a/stream.js +++ b/stream.js @@ -131,16 +131,13 @@ var win = self, t = this, val = 0.0; if(numBytes > 4){ - var i = Math.ceil(numBytes / 4); - while(i--){ - var buff = [], - o = t.offset, - j = o + (numBytes >= 4 ? 4 : numBytes % 4); - while(j > o){ - buff.push(t.readByteAt(--j)); - numBytes--; - t.offset++; - } + var buff=[] + var o = t.offset, + j = o + numBytes; + while(j > o){ + buff.push(t.readByteAt(--j)); + numBytes--; + t.offset++; } var s = new Gordon.Stream(fromCharCode.apply(String, buff)), sign = s.readUB(1),