Advertisement
Data Processing

The Rounding Quantum: Migrating a File Inventory to Display Units Costs Exact Bytes, Rung by Rung

The migration looked harmless on the project plan: a storage inventory that had always stored file sizes as bare byte counts would switch to the frien...

The migration looked harmless on the project plan: a storage inventory that had always stored file sizes as bare byte counts would switch to the friendlier written forms — kilobytes, megabytes — so that reports could be read by humans. The switch was run, the reports looked clean, and only a later audit against the old export noticed that the sizes no longer added up file by file. Nothing had been deleted. Nothing had been corrupted in transit. The new spellings simply could not hold the old numbers: written at two decimal places, a megabyte spelling rounds to the nearest ten thousand bytes, and 228 of the inventory's 240 unit-spelled files came back from parsing with a different byte count than they left with.

What The Rounding Quantum means

The Rounding Quantum means the staircase of rounding steps that two-decimal unit spellings impose on a quantity: each larger unit multiplies the smallest writable step, so the maximum silent error climbs rung by rung — 5 bytes for kilobytes, 5 bytes for kibibytes, about 5,000 bytes for megabytes and about 5,243 bytes for mebibytes. The nearest prior concept is The Widening Step. The Widening Step described a price card on which the ratio between two model tiers widened from one price class to the next — a widening in what a vendor charges. The Rounding Quantum is a widening in what a notation can say: the step that grows is not a price ratio but the quantum, the smallest difference a spelling can express, and it grows by a factor of about a thousand per rung while the value it describes stays exactly the same size. One concept widens a bill; the other widens an error bar.

The Rounding Quantum: Migrating a File Inventory to Display Units Costs Exact Bytes, Rung by Rung

1 Pre-Migration Inventory: 300 Files, Five Ways of Being Written

The measured inventory holds 300 files with distinct byte counts, drawn from about 1.6 KB up to about 2 TB, totalling 25,029,616,838,650 bytes. Before any switch, take the inventory of forms the files arrive in, because the migration's cost depends entirely on the mix. In inventory B the 300 files are spread evenly across five written forms, 60 each: bare bytes; decimal kilobytes at two decimal places; binary kibibytes at two decimal places; decimal megabytes at two decimal places; binary mebibytes at two decimal places. Exact string matching against the byte-count inventory recovers only the 60 bare-byte rows. That is the baseline the migration starts from — and the pre-migration lesson is already visible: four-fifths of the inventory is written in forms that no string comparison will ever reconcile, so the switch will stand or fall on parsing, and parsing is where the ladder waits.

2 Switch Steps and Timing: Parse with the Units Honoured, Then Count What Survives

The switch procedure has two parses, and running both is what separates the two different losses. Step one, a naive parse that reads every unit as 1000-based — the mistake a quick script makes with KiB and MiB — recovers 65 of 300 files. Step two, the full parse that honours the SI and IEC definitions (KB = 1,000 bytes, KiB = 1,024, MB = 1,000,000, MiB = 1,048,576) and rounds to the nearest byte, recovers 72 of 300. The gap between the two parses, 7 files, is the entire cost of the famous 1000-versus-1024 confusion in this inventory. The other 228 unit-spelled files are lost to the ladder itself. Recovery by block under the full parse shows the rungs: bytes 60 of 60; KB 5 of 60; KiB 7 of 60; MB 0 of 60; MiB 0 of 60. The worst absolute errors by block are 0, 5, 5, 4,899 and 5,159 bytes respectively — each just under the half-quantum of its rung (half of 0.01 KB is 5 bytes; half of 0.01 MB is 5,000; half of 0.01 MiB is 5,242.88). Timing matters in one respect: the errors are created at the moment of writing the two-decimal spelling, not at parsing, so the count must be taken against the pre-switch export, while the exact bytes still exist somewhere.

3 The Worked File: 7,117,681,496 Bytes, Written Four Ways

Follow one file through the switch. Its true size is 7,117,681,496 bytes. Written in kilobytes it is "7117681.50 KB"; in kibibytes, "6950860.84 KiB"; in megabytes, "7117.68 MB"; in mebibytes, "6787.95 MiB". Parsed back from the MiB spelling with the units honoured, it returns 7,117,681,459 bytes — 37 bytes short, with no error raised anywhere, because 6,787.95 MiB is a perfectly valid spelling of a slightly different file. The same file parsed from its KB spelling survives or dies by luck: a two-decimal kilobyte spelling can be off by up to 5 bytes, and whether the true count happens to sit on a writable step is chance. One more hazard from the same measurement deserves a line in the migration plan: across the whole 300-file set, 16 small files spell as "0.00 MiB" — a normalisation that writes everything in mebibytes does not merely round those files, it erases their size entirely, and any report summed from such spellings inherits the erasure silently.

4 Parallel Run and Rollback: Keep the Byte Counts Alive Until the New Forms Prove Themselves

The parallel-run arrangement for this switch is dictated by the ladder's asymmetry: the new forms can be generated from the old counts at any time, but the old counts can never be regenerated from the new forms. So run both inventories in parallel for one full reporting cycle, with the byte counts as the system of record and the unit spellings as a display layer computed from them. During the parallel run, reconcile per file, not in aggregate: the totals can agree to six significant figures while 228 individual files are wrong, because the rounding errors point in both directions and cancel in the sum. The rollback plan is then trivially safe if the parallel run was honest — the byte inventory still exists untouched — and impossible if it was not. The one arrangement to refuse is the single-step switch that overwrites counts with spellings: after that step there is nothing to roll back to, only a smoother-looking inventory that is wrong about most of its files by a few thousand bytes each.

Questions on The Rounding Quantum, answered

1. How much of the loss is the 1000-versus-1024 unit confusion? Very little, in this inventory. Reading every unit as 1000-based recovered 65 of 300 files; honouring the IEC units recovered 72. The confusion cost 7 files; two-decimal rounding cost 228 of the unit-spelled files.

2. Why did no megabyte or mebibyte spelling survive the full parse exactly? Because the half-quantum at those rungs — 5,000 bytes for MB, 5,242.88 bytes for MiB — almost never contains the true count. All 120 files in the MB and MiB blocks parsed back to a different byte count; the worst errors were 4,899 and 5,159 bytes.

3. Did any two files collapse into the same spelling? Not inside any single unit block: no two files written in the same unit shared an identical two-decimal spelling. The loss is silent drift of individual values, not collision — except at the bottom of the scale, where 16 files spell as "0.00 MiB".

Red line: never let a two-decimal unit spelling become the system of record for a byte count — above the kilobyte rung its quantum exceeds 5,000 bytes, and an inventory migrated onto such spellings has quietly discarded the exact size of nearly every file it holds.

Know someone who needs this? Share it.

Advertisement