I've been building CraftersCalc, a set of about 100 free calculators for people who quilt, pour candles and make soap. Most of the math is one line. The bugs come from what that one line assumes. Here are three cases.
1. Quilt backing: the seam direction changes the yardage
Backing fabric comes on a bolt with a fixed usable width (about 42 in), so a large quilt needs several lengths sewn together. You can run the seams either way, and the two answers differ.
const panels = Math.ceil(backingDimToCover / fabricWidth); const totalLengthInches = panels * panelLength; For a 60 x 80 in quilt with 4 in of overhang per side, the backing is 68 x 88 in:
- Vertical seams: 2 panels x 88 in = 176 in = 4.89 yd
- Horizontal seams: 3 panels x 68 in = 204 in = 5.67 yd
Same quilt, 0.78 yd apart. So the function computes both and recommends the smaller one.
2. Candle fragrance: percent of what?
A "10% fragrance load" means 10% of the wax weight, not of the finished candle. If you have an 8 oz jar and take 10% of 8, you get 0.8 oz of fragrance and 7.2 oz of wax, which is an 11.1% load.
Working back from the total needs a division:
// total = wax * (1 + load) -> wax = total / (1 + load) waxG = totalG / (1 + load); fragG = totalG - waxG; For the 8 oz jar that gives 7.27 oz wax and 0.73 oz fragrance.
3. Soap lye: a weighted sum, then a discount
Each oil needs a different amount of lye per gram (its SAP value). You sum over the recipe and then hold back a few percent ("superfat") so some oil stays unreacted.
naohGross += o.weight * sap; const naoh = naohGross * (1 - d.superfatPercent / 100); // concentration = lye / (lye + water) -> water = lye * (1 - c) / c waterWeight = naoh * ((1 - c) / c); 500 g of olive oil (SAP 0.134) needs 67 g of NaOH; at 5% superfat that is 63.65 g, with 129.23 g of water at a 33% lye concentration.
This one matters more than the others: too much lye makes a bar that burns skin. Inputs go through a zod schema with hard limits, and an unknown oil is an error, never a guess.
What I took from it
- Keep every formula a pure function with a schema in front of it. All of these run in the browser with no backend.
- Write the unit convention into the code comment. "Percent of wax" versus "percent of total" is the whole bug.
- Compute in one unit (grams) and convert only at the end.
The calculators are free to use at handmadecalculators.com: quilt backing, candle fragrance load, soap lye. If you spot a wrong number, tell me.