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 nurbs/step.js:302 in trimOf ModelCraft, PartCraft
    let seg = c.deg === 1 ? c.cvs.slice() : Array.from({ length: 33 }, (_, i) => C.point(c, a + (z - a) * i / 32));

    === in c.deg === 1. Fine for a value that is set, not computed (a default scale). If it comes from a calculation, use an epsilon. Reviewed: STEP files of NURBS curves and surfaces.

  • Against 1 bodies-ui.js:225 in panel PartCraft
    grid.push(host.check(t('ui.bodies.scale.uniform'), f.uniform, (v) => set(f, t('ui.bodies.undo.uniform'), (g) => { g.uniform = v; if (!v && g.sx === 1 && g.sy === 1 && g.sz === 1) { g.sx = g.s; g.sy = 

    === in g.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 bodies-ui.js:225 in panel PartCraft
    grid.push(host.check(t('ui.bodies.scale.uniform'), f.uniform, (v) => set(f, t('ui.bodies.undo.uniform'), (g) => { g.uniform = v; if (!v && g.sx === 1 && g.sy === 1 && g.sz === 1) { g.sx = g.s; g.sy = 

    === in g.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 bodies-ui.js:225 in panel PartCraft
    grid.push(host.check(t('ui.bodies.scale.uniform'), f.uniform, (v) => set(f, t('ui.bodies.undo.uniform'), (g) => { g.uniform = v; if (!v && g.sx === 1 && g.sy === 1 && g.sz === 1) { g.sx = g.s; g.sy = 

    === in g.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 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 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 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 nurbs/construct.js:86 in revolve ModelCraft, PartCraft
    if (V.len(Z) === 0) fail('nurbs.err.axis');

    === in V.len(Z) === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Surfaces from curves: extrude, ruled, revolve and loft, Fitted curves and surfaces: sweeps, networks, Coons patches, offsets, rebuilds and extensions.

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

  • Against 0 3dm/geom.js:155 in rec PartCraft
    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. Not in the register.

  • Against 0 3dm/tess.js:245 in emit PartCraft
    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. Not in the register.

  • Against 0 cs-lib-linalg.js:536 in symEigen PartCraft
    if (scale === 0) {

    === in scale === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: CraftScript dense linear algebra, CraftScript sparse matrices and direct factorization, CraftScript iterative solvers and sparse eigenvalues.

  • Against 0 cs-tensor.js:181 in unop PartCraft
    if (!A.d) return op === 'neg' ? -A.x : op === 'not' ? A.x === 0 : A.x;

    === in A.x === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: CraftScript array arithmetic.

  • Against 0 hydrostatics.js:136 in rightingArms PartCraft
    const M = ang === 0 ? mesh : heeled(mesh, ang);

    === in ang === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Hull hydrostatics and righting arms.

  • Against 0 magnet-study.js:172 in buildJob PartCraft
    const sources = sp.filter((s, i) => (s.role === 'magnet' && clamp(s.br, 0, 99, 0) > 0) || (s.role === 'coil' && Number(s.current) !== 0));

    !== in Number(s.current) !== 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Magnet study: 2D field, force and torque.

  • Against 0 tetmesh.js:574 in stuffOnce PartCraft
    if (c.t === 0) continue;

    === in c.t === 0. Usually fine as a guard against dividing by zero; check it is not meant to catch a near-zero value too. Reviewed: Tetrahedral mesh of a part.