Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions packages/xls-codec/README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/xls-codec/src/biff/cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ describe("BlockCursor", () => {
expect(cursor.i32()).toBe(-1);
});

it("reads a signed 16-bit integer", () => {
const cursor = new BlockCursor([bytes(0xff, 0xff, 0x02, 0x00)]);

expect(cursor.i16()).toBe(-1);
expect(cursor.i16()).toBe(2);
});

it("reads an Xnum as an IEEE 754 double", () => {
// [MS-XLS] 2.5.342: Xnum is a 64-bit binary floating-point number. 1.5 is 0x3FF8000000000000, little-endian on the wire.
const cursor = new BlockCursor([
Expand Down
5 changes: 5 additions & 0 deletions packages/xls-codec/src/biff/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export class BlockCursor {
return this.u32() | 0;
}

/** A signed 16-bit integer, sign-extended by shifting the raw value out of and back into the low 16 bits -- what XTI's itabFirst/itabLast ([MS-XLS] 2.5.344) and a handful of other structures carry. */
i16(): number {
return (this.u16() << 16) >> 16;
}

/** An Xnum ([MS-XLS] 2.5.342): a little-endian IEEE 754 double. */
f64(): number {
const raw = this.take(8);
Expand Down
Loading