Skip to content
Open
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
3 changes: 2 additions & 1 deletion web/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions web/test/gofixed.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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><td class="v mono">([^<]*)/.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");
Expand Down
Loading