diff --git a/web/src/run.js b/web/src/run.js index 5026a19..79cf2aa 100644 --- a/web/src/run.js +++ b/web/src/run.js @@ -561,8 +561,9 @@ function summaryLine(idx) { // Bits per weight as the card would print it: two decimals at most, and a // figure like 6.5625 (a real UD-Q6_K measurement) does not pretend to four. +// The tie is goFixed. toFixed would print 6.125 as 6.13. function bits(b) { - return Number(b).toFixed(2).replace(/\.?0+$/, ""); + return goFixed(Number(b), 2).replace(/\.?0+$/, ""); } // The figure rows (TTP-130). Every part is copied from the index the client diff --git a/web/test/gofixed.test.mjs b/web/test/gofixed.test.mjs index 6f8bbc2..6eefba2 100644 --- a/web/test/gofixed.test.mjs +++ b/web/test/gofixed.test.mjs @@ -8,6 +8,7 @@ import test from "node:test"; import { fmt } from "../src/page.js"; import { goFixed } from "../src/gofixed.js"; +import { serveRunPage } from "../src/run.js"; test("an exact tie rounds to even, as Go does", () => { assert.equal(goFixed(0.25, 1), "0.2"); @@ -24,6 +25,39 @@ test("fmt uses that tie rule for the figures the page shares with the card", () assert.equal(fmt(0), "?"); }); +test("bits per weight uses that tie rule and keeps at most two decimals", async () => { + const row = { + id: "abcdefgh", + created_at: "2026-09-19T07:00:00Z", + private: 0, + owned: 1, + card_key: null, + tape_ext: ".toktape", + tape_bytes: 100, + }; + async function quant(bits) { + const env = { + DB: { + prepare: () => ({ + bind: () => ({ + first: async () => ({ + ...row, + index_json: JSON.stringify({ schema: 1, quant_raw: "Q6_K", quant_bits: bits }), + }), + }), + }), + }, + }; + const html = await (await serveRunPage("abcdefgh", env, "https://tape.midagedev.com")).text(); + const cell = /quantisation<\/td>([^<]*)/.exec(html); + assert.ok(cell, "no quantisation row"); + return cell[1]; + } + assert.equal(await quant(6.5625), "Q6_K · 6.56 bit"); + assert.equal(await quant(6.125), "Q6_K · 6.12 bit"); + assert.equal(await quant(4.5), "Q6_K · 4.5 bit"); +}); + test("a value that only looks like a tie rounds by its exact value", () => { // 0.15 and 1.45 are stored just under the tie (0.1499…, 1.4499…): Go prints 0.1 and 1.4. assert.equal(goFixed(0.15, 1), "0.1");