Resources Numerical accuracy Calculation policy

Regulation limits in force and how values are written

Gives an app's tools the tightest limit of a rule across the ticked regulation packs, and writes required and found values in problems and on the code summary sheet.

How the precision is kept

The tightest limit is the largest of the minimums and the smallest of the maximums, compared in 64-bit numbers with no arithmetic on the values. Values are rounded only when they are written as text: the checks themselves, in each app's check file, compare unrounded numbers.

Open item. Return the name of the pack that set the tightest value from limit(), which now always names the first ticked pack that has the rule.

Calculations under this policy

4 calculations in 2 source files. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.

addons/regs/lib/adapter.js CadCraft 0.8.2 64-bit 2 calculations Reviewed

Tests None found by the review

Tightest limit of a rule

64-bit

The minimum and maximum a rule allows when several ticked packs have it.

min = max(minᵢ); max = min(maxᵢ)

Comparisons only; the values are not changed. The pack name returned is that of the first ticked pack that has the rule, also when a later pack supplied the tighter value. The result is not checked for a minimum above the maximum.

  • addons/regs/lib/adapter.js
  • lines 63 to 73
  • CadCraft 0.8.2
/** The tightest limit of a rule across the ticked packs: { min, max, pack } or null when none of them has the rule. */
limit(id) {
  let out = null;
  for (const prof of profiles()) {
    const r = prof.rule(id);
    if (!r) continue;
    const b = ruleBounds(r);
    out = out ? { min: b.min === null ? out.min : Math.max(out.min ?? -Infinity, b.min), max: b.max === null ? out.max : Math.min(out.max ?? Infinity, b.max), pack: out.pack } : { min: b.min, max: b.max, pack: prof.name };
  }
  return out;
},

Values written in a problem

64-bit

How a required or found value is written in a regulation problem, by unit.

mm: round(v × 10) ÷ 10; m²: round(v × 100) ÷ 100; ratio and U: 2 decimals; R: 1 decimal; count: whole

Rounding happens in the text only. A U-value is written to two decimals, so 0.035 reads as U-0.04.

  • addons/regs/lib/adapter.js
  • lines 41 to 44
  • CadCraft 0.8.2
const lenText = host.lenText || ((mm) => (Math.round(mm * 10) / 10) + ' mm');
const areaText = host.areaText || ((m2) => (Math.round(m2 * 100) / 100) + ' m²');
const fmt = (v, unit) => (unit === 'pct' ? pct(v) : unit === 'm2' ? areaText(v) : unit === 'count' ? String(Math.round(v)) : unit === 'ratio' ? String(Math.round(v * 100) / 100)
  : unit === 'r' ? 'R-' + (Math.round(v * 10) / 10) : unit === 'u' ? 'U-' + (Math.round(v * 100) / 100) : lenText(v));
addons/regs/lib/ui.js CadCraft 0.8.2 64-bit 2 calculations Reviewed

Tests None found by the review

Percentages as text

64-bit

A percentage written in the panel, in problems and on the code summary sheet.

round(v × 10) ÷ 10, then the browser's number format with at most one decimal

Rounded to one decimal for text only. The decimal mark follows the browser's locale.

  • addons/regs/lib/ui.js
  • line 29
  • CadCraft 0.8.2
export const pct = (v) => (Math.round(v * 10) / 10).toLocaleString(undefined, { maximumFractionDigits: 1 }) + ' %';

Values on the code summary sheet

64-bit

Required and found values on the printable code summary for a permit set.

The same rounding as in problems: ratio and U-value to two decimals, R-value to one, count to a whole number; lengths and areas go through the app's own formatter. A missing value is written as a dash.

  • addons/regs/lib/ui.js
  • line 494
  • CadCraft 0.8.2
const fmtV = (v, unit) => (v === null || v === undefined ? '–' : unit === 'pct' ? pct(v) : unit === 'm2' ? host.areaText(v) : unit === 'count' ? String(Math.round(v)) : unit === 'ratio' ? String(Math.round(v * 100) / 100) : unit === 'r' ? 'R-' + (Math.round(v * 10) / 10) : unit === 'u' ? 'U-' + (Math.round(v * 100) / 100) : host.lenText(v));

In detail

Method
limit = { max of the packs' minimums, min of the packs' maximums }. Text: percent to 0.1, ratio to 0.01, R-value to 0.1, U-value to 0.01, count to a whole number, length to 0.1 mm and area to 0.01 m² unless the app supplies its own formatter.
Number types
64-bit numbers; rounded decimal text on output.
Limits
The same formatter is written out four times, once in adapter.js and three times in ui.js. A written value can read as equal to its limit while the unrounded check failed.

Approach: 64-bit, direct

Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.

Every policy that takes this approach