From 26ff9d27e98e08ecd3f3258362b0b6016e1c733a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 11 Oct 2026 08:45:48 +0200 Subject: [PATCH] numeric-leaves vectors gain two float32 rows; float32 integer rounding drops its redundant guard An odd kept value just past exact pins the tie rule (the Stryker survivor). The excess <= 0 guard was equivalent to the general path for the only values that reach it, so it is deleted. Co-Authored-By: Claude Opus 5.5 --- packages/cultcache-ts/src/codec.ts | 4 ++-- .../cultcache-ts/test/union-parity.test.ts | 2 +- tests/vectors/numeric-leaves/reads.msgpack | Bin 3643 -> 3859 bytes 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cultcache-ts/src/codec.ts b/packages/cultcache-ts/src/codec.ts index c7d2736d..1ad50f8e 100644 --- a/packages/cultcache-ts/src/codec.ts +++ b/packages/cultcache-ts/src/codec.ts @@ -88,11 +88,11 @@ export const int32 = integerCodec("System.Int32", "an int32", -(2n ** 31n), 2n * export const int64 = integerCodec("System.Int64", "an int64", -(2n ** 63n), 2n ** 63n - 1n); // A 64-bit integer to the nearest float32 in one rounding, ties to even, as the reference's cast does. Number(value) -// first would round to a double and then again, and the two roundings can disagree. +// first would round to a double and then again, and the two roundings can disagree. A bigint reaches here only beyond +// 2^53 (the wire reader returns a number for any smaller integer), so at least 30 bits are rounded away. function bigintToFloat32(value: bigint): number { const magnitude = value < 0n ? -value : value; const excess = magnitude.toString(2).length - 24; - if (excess <= 0) return Number(value); const kept = magnitude >> BigInt(excess); const rest = magnitude - (kept << BigInt(excess)); const half = 1n << BigInt(excess - 1); diff --git a/packages/cultcache-ts/test/union-parity.test.ts b/packages/cultcache-ts/test/union-parity.test.ts index 69727b8f..6b31c902 100644 --- a/packages/cultcache-ts/test/union-parity.test.ts +++ b/packages/cultcache-ts/test/union-parity.test.ts @@ -548,7 +548,7 @@ const isNaNBits = (bitsHex: string) => { test("numeric leaves read and refuse exactly what the C# reference does", async () => { const rows = readWire(new Uint8Array(await readFile(join(numericVectors, "reads.msgpack")))) as [string, Uint8Array, boolean, Uint8Array][]; - assert.equal(rows.length, 148); + assert.equal(rows.length, 156); let accepted = 0; let refused = 0; for (const [leaf, payload, wasAccepted, bits] of rows) { diff --git a/tests/vectors/numeric-leaves/reads.msgpack b/tests/vectors/numeric-leaves/reads.msgpack index 45aaf7f42e772f4b881bdbe5a85491143d7996b1..51991ff24fb9298d58855b84582c0119ffd9cc1e 100644 GIT binary patch delta 162 zcmdljGg*%L4#S*{%u5)h&o?kIG5`VNp(6}amS*Oa7#khong|x%JdM$UnH9{OJds6& ziIHLRUY2Rhd~hv?k8n6YnEa4klpAaW1B9Q*AvQUJhi7v#$46#ERJ9BY3P7u-EKkeH WPb@JrfmsByAFLNBzuA@N8zTTYh%X)h delta 32 ocmbO%w_Aq!4#Sj<%u5(IUuINi-mJ#j%DnkC2P4a79p2}R0KKpZ>i_@%