8000 Fix decoding of Float16 with fraction and add a test for it · arduino/cbor-js@65dc496 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65dc496

Browse files
committed
Fix decoding of Float16 with fraction and add a test for it
1 parent 66ccfe3 commit 65dc496

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

cbor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function decode(data, tagger, simpleValue) {
213213
else if (exponent !== 0)
214214
exponent += (127 - 15) << 10;
215215
else if (fraction !== 0)
216-
return fraction * POW_2_24;
216+
return (sign ? -1 : 1) * fraction * POW_2_24;
217217

218218
tempDataView.setUint32(0, sign << 16 | exponent << 13 | fraction << 13);
219219
return tempDataView.getFloat32(0);

test/tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ var testcases = function(undefined) {
298298
"f90400",
299299
0.00006103515625,
300300
true
301+
], [
302+
"Float16 -5.960464477539063e-8",
303+
"f98001",
304+
-5.960464477539063e-8,
305+
true
301306
], [
302307
"Float16 -4.0",
303308
"f9c400",

0 commit comments

Comments
 (0)
0