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.

  • Two computed values unit-table.js:126 in convert CadCraft, BimCraft, ModelCraft, MarkupCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    if (a === b || a.factor === b.factor) return v;

    === in a.factor === b.factor. Compare within a documented epsilon scaled to the size of the geometry, or restructure so one side is exact. Reviewed: Unit conversion, Unit table: reading and writing values.

  • Two computed values stroke-clean.js:143 in cleanStroke MarkupCraft
    const sq = ang !== Math.atan2(last.y - first.y, last.x - first.x);

    !== in ang !== Math.atan2(last.y - first.y, last.x - first.x). Compare within a documented epsilon scaled to the size of the geometry, or restructure so one side is exact. Not in the register.

  • Against 1 areaclip.js:75 in cleanAreaClip CadCraft, BimCraft, MarkupCraft, DetailCraft
    if (!d || typeof d !== 'object' || d.format !== AREA_FORMAT || d.v !== 1) return null;

    !== in d.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Size of a copied area.

  • Against 1 live-crypto.js:329 in verifyAssertion CadCraft, BimCraft, ModelCraft, MarkupCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    if (!sig || !claims || claims.v !== 1 || typeof claims.name !== 'string') return { ok: false, reason: 'format' };

    !== in claims.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Not in the register.

  • Against 1 base-ui.js:580 in scaleFor MarkupCraft
    if (keep) { const s = Math.max(Math.abs(sx === 1 && !grip.key.match(/[ew]/) ? sy : sx), Math.abs(sy === 1 && !grip.key.match(/[ns]/) ? sx : sy)); sx = Math.sign(sx) * s; sy = Math.sign(sy) * s; }

    === in sx === 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Not in the register.

  • Against 1 base-ui.js:580 in scaleFor MarkupCraft
    if (keep) { const s = Math.max(Math.abs(sx === 1 && !grip.key.match(/[ew]/) ? sy : sx), Math.abs(sy === 1 && !grip.key.match(/[ns]/) ? sx : sy)); sx = Math.sign(sx) * s; sy = Math.sign(sy) * s; }

    === in sy === 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Not in the register.

  • Against 1 clip.js:82 in cleanClip MarkupCraft
    if (!d || typeof d !== 'object' || d.format !== CLIP_FORMAT || d.v !== 1 || !Array.isArray(d.items)) return null;

    !== in d.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Area markup with cut-outs, and clipboard placement.

  • Against 1 content-clip.js:86 in cleanContentClip MarkupCraft
    if (!d || typeof d !== 'object' || d.format !== CONTENT_FORMAT || d.v !== 1) return null;

    !== in d.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Carried, stamped and pasted markup geometry.

  • Against 1 markupcraft.js:4498 in recover MarkupCraft
    if (!rec.data?.pdf || !st || st.v !== 1) throw new Error(t('recover.bad'));

    !== in st.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Sheet scale, typed lengths and measured values, Markup geometry while drawing and editing, Drawing comparison by vector paths.

  • Against 1 pdf-read.js:146 in fromPrivate MarkupCraft
    if (!d || typeof d !== 'object' || d.v !== 1 || typeof d.type !== 'string' || !TYPES[d.type] || d.type === 'foreign') return null;

    !== in d.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Annotations and scales read from a PDF.

  • Against 1 records.js:156 in unpackRecords MarkupCraft
    if (!v || typeof v !== 'object' || v.v !== 1 || !Array.isArray(v.records)) return [];

    !== in v.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Not in the register.

  • 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.