Floating-point error caused a calculator to round 4.2 / 0.6 up to an extra bag
A concrete-bag calculator returned 8 bags for a 4.2 cubic foot job that needs exactly 7, because JavaScript evaluates 4.2 divided by 0.6 as 7.000000000000001. The bug wastes a bag and frustrates customers, and a naive Math.ceil approach gets 10 of 200 exact multiples wrong in the tested range. The developer of Toggle9, a set of free calculators, sourced all figures from primary references such as NIST and manufacturer data sheets. He works examples by hand before writing code and separates the maths into a testable module. The fix subtracts a tiny tolerance before rounding up, and the project now has 202 tests across 30 files.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in