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 1 dwg/objects-write.js:818 CadCraft, BimCraft, ModelCraft, TakeoffCraft, CivilCraft
    const rational = ctl.some((p) => p.w !== undefined && p.w !== 1);

    !== in p.w !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: DWG object values written and read.

  • Against 1 dwg/table-write.js:70 in insertScale CadCraft, ModelCraft, CivilCraft, DetailCraft, PartCraft
    if (sx === 1 && sy === 1 && sz === 1) w.BB(3);

    === 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 dwg/table-write.js:70 in insertScale CadCraft, ModelCraft, CivilCraft, DetailCraft, PartCraft
    if (sx === 1 && sy === 1 && sz === 1) w.BB(3);

    === 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 dwg/table-write.js:70 in insertScale CadCraft, ModelCraft, CivilCraft, DetailCraft, PartCraft
    if (sx === 1 && sy === 1 && sz === 1) w.BB(3);

    === in sz === 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 dwg/table-write.js:72 in insertScale CadCraft, ModelCraft, CivilCraft, DetailCraft, PartCraft
    else if (sx === 1) { w.BB(1); w.DD(sy, 1); w.DD(sz, 1); }

    === 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 dxf-model.js:58 in msg CadCraft, BimCraft, TakeoffCraft, CivilCraft
    if (typeof s === 'object') s = s['=' + fills.n] ?? (Number(fills.n) === 1 ? s.one : s.other) ?? s.other;

    === in Number(fills.n) === 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: DXF reading into the shared drawing model.

  • 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 usd/usda-write.js:40 in subLayersText CadCraft, BimCraft, ModelCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    return asset(a) + (o && (o.offset !== 0 || o.scale !== 1) ? ' (' + layerOffsetText(o) + ')' : '');

    !== in o.scale !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Number text in USD files.

  • Against 1 usd/usda-write.js:47 in layerOffsetText CadCraft, BimCraft, ModelCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    if (o.scale !== 1) parts.push('scale = ' + num(o.scale, 'f64'));

    !== in o.scale !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Number text in USD files.

  • Against 1 usd/usda-write.js:172 in listItemText CadCraft, BimCraft, ModelCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    if (o && (o.offset !== 0 || o.scale !== 1)) parts.push(layerOffsetText(o));

    !== in o.scale !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Number text in USD files.

  • Against 1 clip.js:49 in readClip CivilCraft
    if (!obj || typeof obj !== 'object' || obj.format !== CLIP_FORMAT || obj.v !== 1 || !Array.isArray(obj.pts)) return null;

    !== in obj.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 ifc/geo-tri.js:133 in clip BimCraft, TakeoffCraft, CivilCraft, DetailCraft
    if (cross(a, e, c) === 0 && !between(a, e, c)) { remove(e); count--; if (e === stop) stop = c; e = c; if (count < 3) return; continue; }

    === in cross(a, e, c) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Polygon triangulation by ear clipping.

  • Against 0 ifc/geo-tri.js:145 in clip BimCraft, TakeoffCraft, CivilCraft, DetailCraft
    while (p.next !== e) { if (cross(e, p, p.next) !== 0) out.push(e.i, p.i, p.next.i); p = p.next; }

    !== in cross(e, p, p.next) !== 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Polygon triangulation by ear clipping.

  • Against 0 raster.js:118 in openGeoTiff BimCraft, CivilCraft
    const scale = Number.isFinite(meta.scale) && meta.scale !== 0 ? meta.scale : 1;

    !== in meta.scale !== 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Elevation grids read from GeoTIFF and ASCII files.

  • 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 usd/earcut.js:52 in filterPoints CadCraft, BimCraft, ModelCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {

    === in area(p.prev, p, p.next) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Polygon triangulation (ear clipping).

  • Against 0 usd/usda-read.js:476 in component CadCraft, BimCraft, ModelCraft, TakeoffCraft, CivilCraft, DetailCraft, PartCraft
    if (c.k === 'num') { this.i++; return c.v !== 0; }

    !== in c.v !== 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Floats read from USD files.

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

  • Against 0 featureline.js:228 in offsetFeature CivilCraft
    if (!fin(dist) || dist === 0) return { f: null, problem: t('fl.offset.zero') };

    === in dist === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Feature line grades, arcs, offsets and crossings, Feature line arcs as straight pieces.

  • Against 0 gis-cad-ui.js:171 in surveyRun CivilCraft
    const fromBlocks = chosenRefs().map((x) => ({ x: x.x, y: x.y, z: Number.isFinite(x.z) && x.z !== 0 ? x.z : null }));

    !== in x.z !== 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 gis-cad-ui.js:207 in howChoices CivilCraft
    const flat = chosenRefs().every((x) => x.z === 0);

    === in x.z === 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 landxml.js:448 in inf CivilCraft
    const inf = (v) => String(v).trim().toUpperCase() === 'INF' || !Number.isFinite(Number(v)) || Number(v) === 0;

    === in Number(v) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: LandXML export and import.