Resources Numerical accuracy

Equality comparisons

Where the code asks whether two decimal numbers are exactly equal. A floating-point result can differ from another in the last digit after a few transformations, so a mesh run through several of them can change the length of an edge, or miss a match. Compare with < or > where a range is meant, and with a documented epsilon where equality is.

  • 316 comparisons to look at
  • 149 files
  • 175 likely to matter (against a decimal, or two computed values)
  • Scanned

Equality comparisons

These are places worth checking, not confirmed bugs. The scan reads how the code is written, not what it is meant to do, so some entries are fine as they are: a test against exactly 0 is often a deliberate guard against dividing by zero. It skips text, counts and indexes, and any comparison it cannot be sure involves decimal numbers, so there are likely more in the code than are listed here.

  • Against 0 lencalc.js:130 in term CadCraft, ModelCraft, MarkupCraft, TakeoffCraft, CivilCraft, DetailCraft
    if (o.t === '/' && b.v === 0) throw new CalcError('divide', o.pos);

    === in b.v === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Arithmetic on typed lengths.

  • Against 0 wheel-pad.js:20 in isSwipe CadCraft, BimCraft, MarkupCraft, TakeoffCraft, CivilCraft
    const step = dx === 0 && ((Number.isFinite(e.wheelDeltaY) && e.wheelDeltaY !== 0 && e.wheelDeltaY % 120 === 0) || (Number.isInteger(dy) && Math.abs(dy) >= 50));

    === in dx === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Not in the register.

  • Against 0 wheel-pad.js:22 in isSwipe CadCraft, BimCraft, MarkupCraft, TakeoffCraft, CivilCraft
    if (dx !== 0 || !Number.isInteger(dy) || Math.abs(dy) < 50) { this.until = t + 400; return true; }

    !== in dx !== 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Not in the register.