Skip to content

Commit f0ab71b

Browse files
committed
FIX: Bincode - read FB was not handling negative numbers correctly
1 parent 4e8896a commit f0ab71b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/core/u-bincode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ static REBCNT EncodedU32_Size(u32 value) {
12541254
if (cmd == SYM_SB) {
12551255
SET_INTEGER(temp, u);
12561256
} else {
1257-
SET_DECIMAL(temp, (double)u / 65536.0);
1257+
SET_DECIMAL(temp, ((double)((i64)u) / 65536.0));
12581258
}
12591259
break;
12601260
case SYM_BIT:

src/tests/units/bincode-test.r3

+3
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ is-protected-error?: func[code][
247247
--assert [-2 6] = binary/read 2#{1110 0110} [SB 4 SB 4]
248248
--assert 14 = binary/read/with 2#{1110 0000} 'UB 4
249249
--assert [2.5] = binary/read #{500000} [FB 19]
250+
binary/read 2#{11111000 11111000} [x: SB 6 ALIGN y: FB 6]
251+
--assert -2 = x
252+
--assert -2.0 = (y * 65536.0)
250253

251254
--test-- "BinCode - bits (variant using sigle value access)"
252255
bin: binary #{438E9438}

0 commit comments

Comments
 (0)