Notes › Life Essays › Two gallons, two horsepower ratings, two byte prefixes: ask which one first

Two gallons, two horsepower ratings, two byte prefixes: ask which one first

One name, two sets of factors underneath

An "add 1 gal" in a recipe, "110 hp" on a spec sheet, mmHg on a blood pressure monitor, and the capacity missing from a new hard drive as soon as you open it: the trouble is never multiplication, it is which definition the name refers to. The factor is fixed; what goes wrong is picking the wrong one. The unit-convert.html template is 12037 bytes and 227 lines, with 10 categories and 110 units at runtime (15 length, 14 weight, 14 area, 14 volume, 4 temperature, 8 speed, 12 time, 11 data storage, 10 pressure, 8 power), and the four pairs below sit side by side inside the same category.

QuantityTwo spellings and factorsMeasured residual difference
Volume: gallongal 3.785411784 / gal(UK) 4.546090.7606782160000005 difference in liters
Power: horsepowerhp 745.6998715823 / PS 735.4987510.201121582300061 W difference, 1.3870% larger and 1.3680% smaller
Pressure: mercury columnmmHg 133.322387415 / Torr 133.3223684210.000014435440007787292 kPa difference at 760
Storage: byteKB 1000 / KiB 1024MB and MiB differ by 48576 B

Gallons differ by a fifth, horsepower by the fifth decimal

The two gallon rows do not just display different values: with US units as the source, cubic inches is exactly 231 and the imperial gallon row reads 0.83267418; with imperial as the source, the US gallon shows 1.2009499. Imperial is 20.0950% larger than US, and US is 16.7326% smaller than imperial. Saying "about 20%" hides the base, and the unit converter will not decide for you which gal a recipe means; it only shows both sides on one screen.

Two more are subtler: 1 hp converted to foot-pounds per second displays 550, but the raw value is 550.0000000127599, so the identity does not hold exactly. The 0.000014435440007787292 kPa between mmHg and Torr comes from truncation: 101325 ÷ 760 = 133.32236842105263, the code stores 133.322368421, an error of -5.263700586510822e-11 pascals. That pair is better described as one definition with two approximations than as two definitions.

US gallon gal 3.7854118 L Imperial gallon gal(UK) 4.54609 L Mechanical hp 745.69987 W Metric hp PS 735.49875 W 760 mmHg 101.32501 kPa 760 Torr 101.325 kPa

Figure 1 | Measured display values for three pairs of same-named units in the template function. Bars are scaled to the larger value within each pair only, so pairs are not comparable; the last pair differs at the sixth digit, already beyond visual resolution.

Two byte systems: the gap grows from 48576 to 99511627776

Among the 11 data storage units, KB at 1000 and KiB at 1024 both exist. 1 MiB is 1,048,576 bytes and displays 1.048576 MB; 1 MB is 1,000,000 bytes and displays 0.95367432 MiB. The gap grows from 48576 bytes at the MB level (ratio 1.048576) to 73741824 at the GB level (1.073742) and 99511627776 at the TB level (1.099512), and 1 TiB in bytes displays 1.099512e+12 outright.

This is a fight over the radix, which is a different matter from base 2, 8 or 16 (to see the same number in another base, use the number base converter), and it is not the same as encoded byte counts either (that belongs to word and byte counting). The line in the copy about "KB/KiB for storage capacity and network speed, Mbps and MB/s" needs rewording: this category is all pure quantities, and Mbps and MB/s each appear 0 times in the template.

Temperature does not use a factor

The four temperature rows have no factor column; the formula row is fixed at Fahrenheit = Celsius × 9 ÷ 5 + 32 and Kelvin = Celsius + 273.15, so -40 ℃ converts to -40 Fahrenheit, and the same row also gives K 233.15 and °R 419.67, while 0 ℃ produces 32, 273.15 and 491.67. The fourth unit's interface name is "Fahrenheit scale (absolute)" with the symbol °R, which is Rankine in the copy, though the interface never shows that word.

How many digits the result keeps: the "8 significant digits" claim holds for only 13 magnitudes

The FAQ says results keep 8 significant digits, but the code says otherwise: dp is 7 minus the integer part of log10, then clamped to 0 through 12. Shifting the same string 1.23456789012345 across magnitudes, only the 13 settings with k from -5 to 7 give exactly 8 digits; at k = -6 there are only 7 digits, k = 8 turns it into 123,456,789 with 9 digits, and k = 11 gives 123,456,789,012 with 12 digits.

1e-6 0.000001234568 · 7 digits 1e-5 0.000012345679 · 8 digits 1e7 12,345,679 · 8 digits 1e8 123,456,789 · 9 digits 1e11 123,456,789,012 · 12 digits 1e12 1.234568e+12 · 7 digits

Figure 2 | Display and digit count produced by the formatting function for the same 1.23456789012345 string at different magnitudes, with bars scaled by digit count.

The scientific notation threshold is loose too: the rule is an absolute value greater than or equal to 1e12, so 1e12 itself prints 1e+12, while 999999999999.9999 rounds up to 1,000,000,000,000 with 13 digits; the lower bound is below 1e-6. Thousands separators are added only in the decimal branch, so 8e11 shows 800,000,000,000 while 8e12 shows 8e+12. Showing 11 or 15 rows at once only makes sense on a single screen; all it saves you is missing the other row.

Copy, reverse conversion, and that upside-down mu and fen table

Copy and reverse conversion get their precision from different sources: copying row by row gives the display string (the KB row 1,048.576, the TiB row 9.536743e-7, commas included), while reverse conversion reads data-val, applies toPrecision(12) and writes it back into the input: 1 mu in square meters displays 666.66667 with a raw value of 666.6666666666666, and after the reverse conversion the input becomes 666.666666667, which converts back to 1 mu, flattening the true 1.0000000000005. The source unit row has no reverse button; only 14 of the 15 length rows have one.

In the area category, 1 mu in square meters displays 666.66667, ping (400 / 121) is 3.3057851, and 1 hectare converts to exactly 15 mu or 3,025 ping, all of which hold up. The problem is fen: the code stores 20000 / 3 (template line 57), which gives 6,666.6667 square meters, so 1 mu to fen displays 0.1 and 1 fen to mu displays 10 (raw value 10.000000000000002). The usual definition is 1 mu = 10 fen; here the ratio is inverted by a factor of 100.

Q: Why does -40 degrees Celsius read back as -40?

The offset formula intersects itself at this point, and both directions land exactly on -40. It is the only point where the two scales meet, not a rounding artifact.

Q: Why is 1 MB sometimes 1048576 bytes?

That is the MiB value: 1 MiB is 1,048,576 bytes and 1 MB is 1,000,000 bytes, a difference of 48576. Whether the name has an i is the dividing line.

Q: Why do large numbers switch to e notation, and can it be turned off?

When the absolute value reaches 1e12 or falls below 1e-6 it switches to scientific notation with a fixed 7 digits, and there is no switch in the code. Multiplying before dividing also treats the intermediate value as the ceiling: with the extreme input 1e308 in km, all 15 rows become dashes, including the 5 rows whose true values were representable; empty input, abc and 1e400 all fall back to "Please enter a value to convert".

📎 Related articles

A photo rotated 90° lies flat again on another device: how the EXIF flag and a real rotation split the work 2026-10-22 Same Day Every Month Versus Every 28 Days, 29 Days Apart Within a Year 2026-10-22 Shuffling with a random sort comparator is already unfair 2026-10-21 Born on 29 February: which day you turn 18 in a common year 2026-10-21 What pace does a 3:30 marathon need? Nine segments, negative splits and the floor pace 2026-10-21