September 29, 2026

Exact decimal math, not floating point

Every quote calculator ends with a number someone might actually charge a customer, so it has to be right — not “right to 15 decimal places” right, exactly right.

JavaScript’s Number can’t promise that. 0.1 + 0.2 doesn’t equal 0.3 in floating point, and there’s a hard ceiling around 2^53 before integers start silently losing precision. Fine for a lot of things; not fine for a price.

So tinymath’s math doesn’t run in JS at all. It runs in a small Rust engine (built on the bigdecimal crate), compiled to WebAssembly, exposed as two functions: calc(a, op, b) and cmp(a, b). A number stays a decimal string from the moment it’s typed to the moment it’s displayed — it’s never coerced into a JS Number in between.

One rule enforces this everywhere: every calculator number goes through the WASM engine, whatever its digit count. Division keeps 100 significant digits, and dividing by zero returns “can’t calculate” instead of Infinity.

The engine adds about 49 KB gzipped. Worth it — two different math engines quietly giving two different answers to the same formula is a much worse bug than a slightly larger download.

← All posts