Resources Numerical accuracy

Calculations

Every calculation under our calculation policies: what it works out, its formula and the precision it runs at. Open one to see its code as it is in the released app.

  • 6,917 calculations in 1,248 source files
  • 143 exact
  • 6,286 in 64-bit
  • 335 with a 32-bit step
  • Last reviewed

Calculations

  • Number text for the command line

    Writes a value taken from the pointer as text.

    text = value rounded to 10 decimals, trailing zeros dropped

    Dynamic input: points from typed distance, angle, X and Y dynin.js
    • CadCraft
    64-bit
  • Unit factors

    What a number with a unit is multiplied by to give millimeters or degrees.

    mm 1; cm 10; m 1000; in 25.4; ft 304.8; deg 1; rad 180 ÷ π

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • A number with a unit

    Reads a number and converts it by the unit written right after it.

    v = Number(text) × factor

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Sine, cosine and tangent in degrees

    sin, cos and tan of an angle given in degrees.

    sin(x) = clean(Math.sin(x × π ÷ 180)); tan refused when |cos| < 1e-12

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Trig result rounded to 15 digits

    Rounds a sine, cosine or tangent to 15 significant digits and turns a value below 1e-15 into 0.

    |x| < 1e-15 → 0; otherwise Number(x.toPrecision(15))

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Inverse trigonometry and square root

    asin, acos, atan, atan2 in degrees, and sqrt.

    asin(x) = Math.asin(clamp(x, −1, 1)) ÷ (π ÷ 180); sqrt(x) = √max(0, x)

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Power, exponential and logarithms

    pow, exp, ln and log.

    pow(a, b) = aᵇ; ln and log need x > 0

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • ceil, floor and int

    Rounds up, down or toward zero to a whole number.

    ceil(x) = ⌈x − ε⌉; floor(x) = ⌊x + ε⌋; int(x) = trunc(x + sign(x) × ε); ε = 1e-9 × max(1, |x|)

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • round(x, digits)

    Rounds to a number of decimal places from 0 to 10, halves away from zero.

    y = |x| × 10ᵈ; r = ⌊y + 0.5 + 1e-9 × max(1, y)⌋; result = ± r ÷ 10ᵈ

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Comparisons

    The six comparison operators, giving 1 or 0.

    tol = 1e-9 × max(1, |a|, |b|); a == b when |a − b| ≤ tol; a < b when a < b − tol

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Arithmetic operators

    Addition, subtraction, multiplication, division, remainder and power.

    a % b = a − b × ⌊a ÷ b⌋; division and remainder refuse b = 0

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • Number as text

    The text a number is written as when it is put back into an expression or a message.

    Number(v.toPrecision(12)) as text

    Parameter expressions expr.js
    • CadCraft
    • BimCraft
    • PartCraft
    64-bit
  • What a dimensional constraint measures

    The current horizontal, vertical or direct distance, radius, diameter or angle of the constrained geometry.

    hdist = s × (x₁ − x₀); dist = |p₁ − p₀| or s × signed distance from the line; diameter = 2r; angle = s × atan2(u × v, u · v) × 180 ÷ π; arc angle = (a₁ − a₀) mod 2π in degrees

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Signed distance from a line

    How far a point or a circle's center lies from an infinite line, positive on the left of its direction.

    d = (u_x × (p_y − l_y) − u_y × (p_x − l_x)) ÷ |u|

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Angle constraint: legs and sign

    Which direction along each line the angle is measured between, and whether it turns counterclockwise.

    parallel when |u × v| < 1e-9 × |u| × |v|; sign = sign of atan2(u′ × v′, u′ · v′)

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Tangent circles: inside or outside

    Decides whether two circles made tangent touch from inside or from outside.

    internal when |c_b − c_a| < max(r_a, r_b) − 1e-12

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Crossing point of two lines

    Where two infinite lines meet, used as the corner of an angle constraint.

    den = d₁ × d₂; t = ((l₂ − l₁) × d₂) ÷ den; x = l₁ + d₁ × t

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Foot of a perpendicular

    The point of a line nearest to a given point.

    t = ((p − l₁) · u) ÷ (u · u); foot = l₁ + t × u

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Mirror gap

    How far a point is from being the mirror image of another across a line.

    f = foot of a on the line; gap = 2f − a − b

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Value rounded to 6 decimals

    Rounds a constraint's value to a millionth of a unit for its label and its parameter text.

    Math.round(v × 1e6) ÷ 1e6

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Constraint value as a parameter

    Creates the parameter for a dimensional constraint read from a file that lacks one.

    expr = formatNumber(round6(value))

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Label value

    The number shown in a dimensional constraint's label.

    text = formatNumber(round6(v)), with ° for angles

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Did solving collapse an object

    Refuses a solution that shrinks a line, a polyline segment or a radius to almost nothing.

    collapsed when new < 1e-6 × old and old > 1e-9

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Which fields an edit moved

    Finds the coordinates an edit changed, so the solver holds them where the edit put them.

    moved when |before − after| > 1e-12 × max(1, |before|)

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • Fixed values moved on paste

    Shifts the stored position of a fix constraint by the paste offset.

    x′ = x + dx; y′ = y + dy

    Constraint values and signs gcons.js
    • CadCraft
    64-bit
  • 8-byte base-16 real

    Converts the stream format's excess-64 base-16 real (units, magnification, angle) to a number.

    value = sign × (m ÷ 2⁵⁶) × 16^(e − 64), m = the 7 mantissa bytes as one integer

    GDSII layout read and placement gds.js
    • CadCraft
    64-bit
  • Reference transform

    The matrix that places one cell reference: reflect, magnify, rotate, move, and its product with the parent's matrix.

    r = angle × π ÷ 180; M = [mag·cos r, mag·sin r, −f·mag·sin r, f·mag·cos r, x, y], f = −1 when reflected

    GDSII layout read and placement gds.js
    • CadCraft
    64-bit
  • Flattened coordinates, array steps and path width

    Places every element of every referenced cell and array and converts its points and width to user units.

    array step = (corner − origin) ÷ count; point = (M × p) × userUnit; width = w × √(M₀² + M₁²) × userUnit

    GDSII layout read and placement gds.js
    • CadCraft
    64-bit
  • Arc of a polyline segment

    The center, radius and angles of a polyline's arc segment from its two vertices and its bulge.

    θ = 4·atan(b); r = |c ÷ (2·sin(θ ÷ 2))|; h = r·cos(θ ÷ 2); center = chord midpoint ± h along the chord's normal

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Angle on an arc

    Whether an angle lies on the counter-clockwise sweep of an arc.

    d = (a − a0) mod 2π; on the arc when d ≤ sweep + tol or d ≥ 2π − tol

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Arc angle range

    Puts an arc's two stored angles in counter-clockwise order with the end after the start.

    a0, a1 reduced to [0, 2π); a1 += 2π when a1 ≤ a0 + 1e-9

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Polyline segments

    The straight and arc pieces of a polyline, one per pair of vertices.

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Point at a parameter

    The point a fraction t of the way along a line or arc.

    line: p₁ + (p₂ − p₁)·t; arc: c + r·(cos a, sin a), a = a0 + (a1 − a0)·t

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Nearest parameter

    The parameter of the point on a line or arc closest to a given point.

    line: t = (q − p₁)·(p₂ − p₁) ÷ |p₂ − p₁|²; arc: t = ((atan2(q − c) − a0) mod 2π) ÷ sweep

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Length of a piece

    The length of a straight segment or an arc.

    line: √(Δx² + Δy²); arc: r × (a1 − a0)

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Intersections on both pieces

    The points where two pieces meet, limited to the pieces themselves unless one is to be treated as unbounded.

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Bounds of a piece

    The smallest box round a line or arc, used for the drawing's extents.

    arc: its two ends and each of the points at 0, π ÷ 2, π, 3π ÷ 2 that is on the sweep

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Tangent points from a point

    The points on a circle where a line from a given point touches it.

    a = atan2(p − c); b = acos(r ÷ d); touch points = c + r·(cos(a ± b), sin(a ± b))

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Lines tangent to two circles

    The outer and inner lines that touch two circles, as pairs of touch points.

    k = (r₁ − s·r₂) ÷ d, s = +1 outer, −1 inner; g = acos(k); n = (cos(base ± g), sin(base ± g)); points = c₁ + r₁·n and c₂ + s·r₂·n

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Object snap points

    The end, middle, center, quadrant, perpendicular, tangent and nearest points of an object that a new point can be placed on.

    middle of a line = (p₁ + p₂) ÷ 2; arc points = c + r·(cos a, sin a)

    Line and arc primitives geom.js
    • CadCraft
    64-bit
  • Composing two transforms

    The single transform that applies n first and then m.

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Mirror across a line

    The transform that reflects across the line through two points.

    a = atan2(q − p); M = [cos 2a, sin 2a, sin 2a, −cos 2a] about p

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Scale and rotation of a transform

    The uniform scale factor, rotation and handedness of a matrix, or nothing when it shears or stretches.

    sx = √(a² + b²); sy = √(c² + d²); rotation = atan2(b, a); mirrored when a·d − b·c < 0

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Inverse transform

    The transform that undoes a given one.

    det = a·d − b·c; inverse = [d, −b, −c, a, c·f − d·e, b·e − a·f] ÷ det

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Block reference matrix

    The transform from a block's own coordinates to where a reference places it.

    M = T(x, y) · R(rotation) · S(sx, sy) · T(−base)

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Viewport matrix

    The transform from model coordinates to paper coordinates for a layout viewport, at its scale and twist.

    no twist: [s, 0, 0, s, x − cx·s, y − cy·s]; twisted: c = s·cos tw, n = s·sin tw, [c, n, −n, c, x − (c·cx − n·cy), y − (n·cx + c·cy)]

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Viewport view center

    Converts a viewport's view center between the file's display coordinates and the model point shown at the viewport's center.

    x = tx + cos tw·dx + sin tw·dy; y = ty − sin tw·dx + cos tw·dy

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Transforming an object

    A copy of a drawing object put through a move, rotation, scale or mirror.

    point: M·p; arc: angles = atan2(M·end − M·center); radius, text height, block scale × s

    Move, rotate, scale and mirror geom.js
    • CadCraft
    64-bit
  • Offset of a line, circle or arc

    A copy of the object a set distance to one side.

    line: p ± d·n, n = (−Δy, Δx) ÷ L; circle, arc: r ± d

    Offset, extend, break and lengthen geom.js
    • CadCraft
    64-bit
  • Offset of a polyline

    A polyline offset to one side, with its corners rebuilt.

    Offset, extend, break and lengthen geom.js
    • CadCraft
    64-bit

A calculation is added only after its source was read. Each statement can be checked in the code shown on its policy's page; the app repositories are public. When a release changes a calculation, its page says so until it has been read again.