Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

When the tape says 1,502 mm: comparing diagonals without premature rounding

Disclosure: This article was drafted by an AI agent for the Pro² developer account. The numbers in the example were checked independently. A tape measure gives you a real number, not a neat 3–4–5 triangle. Suppose a fra

Disclosure: This article was drafted by an AI agent for the Pro² developer account. The numbers in the example were checked independently.

A tape measure gives you a real number, not a neat 3–4–5 triangle. Suppose a frame's adjacent sides measure 1,197 mm and 903 mm. What should the diagonal read? What do you tell someone whose tape reads 1,502 mm?

Keep the calculation and display precision apart

Use the same unit for both sides and the measurement. Compute the target from the actual sides, then subtract it from the tape reading. Round the result for display only. A positive difference means the reading is longer than the target.

function checkDiagonal(aMm, bMm, measuredMm) {
  if (![aMm, bMm, measuredMm].every(n => Number.isFinite(n) && n > 0)) {
    throw new RangeError('Enter positive lengths in millimetres');
  }
  const targetMm = Math.hypot(aMm, bMm);
  return { targetMm, differenceMm: measuredMm - targetMm };
}

const first = checkDiagonal(1197, 903, 1502);
const second = checkDiagonal(1197, 903, 1498);
console.log(first.targetMm.toFixed(1));     // 1499.4
console.log(first.differenceMm.toFixed(1)); // 2.6
console.log(second.differenceMm.toFixed(1)); // -1.4

If you round the target to 1,499 mm first, the same measurements appear to be +3 mm and −1 mm. The tape never changed. The order of operations did.

Tell the user what to measure next

One reading alone does not tell you whether the opposite edges match or whether the tape was hooked on the same reference point. Measure both diagonals between the same inside or outside corner references. Compare both against the target. For this example the two tape readings also differ from each other by 4 mm. Keep that comparison distinct from either reading’s difference from the target.

A calculator can report the target, the direction and the amount of the difference. The project and the way it will be built determine what tolerance is acceptable. If an interface also accepts inches and feet, convert once to a common length unit before subtracting and label the unit on every result.

You can reproduce both readings, one at a time, in the Pro² Square Check browser calculator. The author account belongs to the developer of Pro². The browser calculator is the demonstration for this example.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.