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 flow-study.js:82 in readFlow PartCraft
    if (typeof raw !== 'object' || Array.isArray(raw) || raw.v !== 1) bad(t('study.flow.err.bad_study'));

    !== in raw.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Flow study: fluid cells, openings and wall distances, Flow study: 32-bit steps in the mesh and the result fields.

  • Against 1 sim.js:80 in readSimStudy PartCraft
    if (!raw || typeof raw !== 'object' || Array.isArray(raw) || raw.v !== 1) bad(t('study.sim.err.bad_study'));

    !== in raw.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Study set-up: element size and the mesh handed to the solver.

  • Against 1 sim.js:97 in readGenStudy PartCraft
    if (!raw || typeof raw !== 'object' || Array.isArray(raw) || raw.v !== 1) bad(t('study.sim.err.bad_gen'));

    !== in raw.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Study set-up: element size and the mesh handed to the solver.

  • Against 1 swmacro.js:1569 in partToSwb PartCraft
    if (info.factor !== 1) rhs = `(${rhs}) * ${formatNumber(info.factor)}`;

    !== in info.factor !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Numbers written into the VBA macro export.

  • Against 1 assets/js/addon-license.js:50 in verifyEntitlement Shared shell, every app
    if (!payload || payload.v !== 1 || !Number.isFinite(payload.exp)) return { ok: false, reason: 'bad-signature' };

    !== in payload.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 assets/js/calc.js:240 in dimText Shared shell, every app
    d.forEach((x, i) => { if (Math.abs(x) < 1e-9) return; const s = BASE_NAMES[i] + (Math.abs(x) === 1 ? '' : '^' + sig(Math.abs(x), 3)); (x > 0 ? top : bot).push(s); });

    === in Math.abs(x) === 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Calc sheets, Calc sheet units, functions and driven parameters.

  • Against 1 assets/js/live-crypto.js:329 in verifyAssertion Shared shell, every app
    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 carbon.js:32 in readCarbon TakeoffCraft
    if (!json || typeof json !== 'object' || json.v !== 1) return null;

    !== in json.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Embodied carbon from quantities, Rates exported as a price table.

  • Against 1 prices.js:31 in readStore TakeoffCraft
    if (!json || typeof json !== 'object' || json.v !== 1) return s;

    !== in json.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 supply.js:99 in readSupply TakeoffCraft
    if (!json || typeof json !== 'object' || json.v !== 1) return null;

    !== in json.v !== 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: Supplier stock and lead-time check.

  • Against 0 assembly-preview.js:11 in assemblyDimensionLayout BimCraft
    const label=`${i+1}: ${format(l.t)}${l.t===0?' *':''}`,half=Math.min(450,label.length*4+8);

    === in l.t===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 assembly-schedule.js:51 in assemblySchedules BimCraft
    const designation=cavity?tr('asched.cavity.vent',{vent:l.ventilation}):membrane?(l.t===0?tr('asched.membrane.zero'):tr('asched.membrane.nominal')):tr('asched.material');

    === in l.t===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 framing.js:215 in panelSvg BimCraft, DetailCraft
    const rise = p.h, run = p.w, left = p.x === 0;

    === in p.x === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Framing panels and cut lists.

  • Against 0 framing.js:324 in placePanel BimCraft, DetailCraft
    const left = pc.x === 0, n = c + sz.face / 2;

    === in pc.x === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Framing panels and cut lists.

  • Against 0 framing.js:353 in panelPage BimCraft, DetailCraft
    const left = pc.x === 0;

    === in pc.x === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Framing panels and cut lists.

  • 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 wall-assemblies-ui.js:51 in totals BimCraft
    preview.append(el('div',{style:`position:absolute;box-sizing:border-box;left:${span.start/10}%;width:${(span.end-span.start)/10}%;height:100%;background:${l.kind==='cavity'?'transparent':materialBackg

    === in l.t===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 wall-assemblies-ui.js:54 in totals BimCraft
    membraneNote.hidden=!recipe.layers.some(l=>l.t===0);

    === in l.t===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 wall-assemblies-ui.js:81 in draw BimCraft
    const useDefault=button(mt('useDefault'),()=>{const m=materials.find(m=>m.id===layer.materialId);if(m){layer.t=m.defaultThickness;if(layer.t===0)layer.function='membrane';draw();}},{disabled:layer.kin

    === in layer.t===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 wall-plan-graphics.js:106 in wallPlanGraphics BimCraft
    const polys = layer.t === 0 ? [] : pieces.map(p => clip(clip(p, 1, Math.min(off, end), 1), 1, Math.max(off, end), -1)).filter(p => p.length >= 3).map(p => mappedPath(p, map, true));

    === in layer.t === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Wall layers drawn in plans and sections.

  • Against 0 wall-plan-graphics.js:111 in wallPlanGraphics BimCraft
    if (layer.t === 0) boundaries.set(off, { offset: off, membrane: true, color: material.fillColor });

    === in layer.t === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Wall layers drawn in plans and sections.

  • Against 0 wall-section-graphics.js:139 in wallSectionGraphics BimCraft
    if(l.t===0)boundaries.set(off,{offset:c+off*lateral,membrane:true,color:mat.fillColor});

    === in l.t===0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Wall layers drawn in plans and sections.

  • Against 0 addons/trusscraft/lib/design.js:130 in designTruss CadCraft, BimCraft, ModelCraft, PartCraft
    const closed = g.profile ? g.nodes.find((n) => n.x === 0 && n.z === 0) : true;

    === in n.x === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Truss member forces and timber checks.

  • Against 0 addons/trusscraft/lib/design.js:130 in designTruss CadCraft, BimCraft, ModelCraft, PartCraft
    const closed = g.profile ? g.nodes.find((n) => n.x === 0 && n.z === 0) : true;

    === in n.z === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Truss member forces and timber checks.

  • 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 lisp/dxflist.js:152 in fromPairs CadCraft
    else if (has(62)) { const c = get(pairs, 62); e.color = c === 256 ? null : Math.abs(c) === 0 ? 0 : Math.min(255, Math.abs(c)); }

    === in Math.abs(c) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Drawing values handed to and from LISP routines.

  • Against 0 m3d/earcut.js:51 in filterPoints CadCraft, TakeoffCraft
    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: Triangulation of faces with holes.

  • Against 0 m3d/lencalc.js:130 in term CadCraft
    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. Not in the register.

  • Against 0 m3d/tools.js:727 in value CadCraft
    if (!Number.isFinite(deg) || deg === 0) return false;

    === in deg === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: 3D drawing and editing tools.

  • Against 0 m3d/tools.js:1138 in pickPoint CadCraft
    this.k = 1 / Math.max(len(this.T.localDir(this.n)), 1e-9) === 0 ? 1 : len(this.T.localDir(this.n));

    === in 1 / Math.max(len(this.T.localDir(this.n)), 1e-9) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: 3D drawing and editing tools.

  • Against 0 pointcloud.js:721 in scanPtx CadCraft, BimCraft
    if (px === 0 && py === 0 && pz === 0) { missing++; return; }

    === in px === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Point cloud positions and read-in values.

  • Against 0 pointcloud.js:721 in scanPtx CadCraft, BimCraft
    if (px === 0 && py === 0 && pz === 0) { missing++; return; }

    === in py === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Point cloud positions and read-in values.

  • Against 0 pointcloud.js:721 in scanPtx CadCraft, BimCraft
    if (px === 0 && py === 0 && pz === 0) { missing++; return; }

    === in pz === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Point cloud positions and read-in values.

  • Against 0 process/env/cheminfo.js:182 in groupsOf CadCraft, BimCraft
    if (arom) inc(a.h === 1 ? 'ring =CH-' : a.h === 0 ? 'ring =C<' : 'ring =CH-');

    === in a.h === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Molar mass and group-contribution estimates.

  • Against 0 process/env/cheminfo.js:189 in groupsOf CadCraft, BimCraft
    else if (a.h === 0 && nb[i].length === 2 && !inRing[i] && nb[i].every((x) => x.order === 1 && !mol.atoms[x.o].aromatic)) inc('-O- (non-ring)');

    === in a.h === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Molar mass and group-contribution estimates.

  • Against 0 process/equip/pipestress.js:109 in buildModel CadCraft, BimCraft
    const W = { id: 'W', name: 'Weight', kind: 'dead', selfWeight: 1, loads: fm.members.map((e) => ({ type: 'udl', member: e.id, dir: 'Z', w: -(wContents + wIns) })).filter((l) => l.w !== 0) };

    !== in l.w !== 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Pipe stress checks.

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

  • Against 0 earcut.js:51 in filterPoints ModelCraft
    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. Not in the register.

  • Against 0 io/3dm/earcut.js:52 in filterPoints ModelCraft
    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. Not in the register.

  • Against 0 io/3dm/geom.js:155 in rec ModelCraft
    if (chordDev(pm, pa, pb) > tol || chordDev(q1, pa, pb) > tol || chordDev(q3, pa, pb) > tol || (depth < 2 && dist(pa, pb) === 0 && dist(pm, pa) > tol)) {

    === in dist(pa, pb) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: 3DM curves and surfaces: points on them.

  • Against 0 io/3dm/tess.js:245 in emit ModelCraft
    if (ar === 0) { const n = cross(sub(pos(c), pos(a)), sub(pos(d), pos(a))); if (len(n) === 0) return; }

    === in len(n) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: 3DM surfaces into triangles.