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

  • Machining time

    The time a program takes: cutting moves at their feed, rapid moves at the machine's rapid rate, plus tool changes.

    seconds = 60 × (Σ L ÷ feed + Σ L ÷ rapid) + changes × change time

    Stock simulation and machining time cam-sim.js
    • PartCraft
    64-bit
  • Arc center words I and J

    The arc center written relative to the arc's start point.

    I = round₃(c_x − round₃(start_x)); J = round₃(c_y − round₃(start_y))

    G-code and toolpath exports cam-post.js
    • PartCraft
    64-bit
  • Axis words

    Writes X, Y and Z only when they change at the output resolution.

    write an axis when round₃(new) ≠ round₃(last written)

    G-code and toolpath exports cam-post.js
    • PartCraft
    64-bit
  • Toolpath as CSV

    Writes every segment's start, end, arc center, sweep and feed as text.

    value = toFixed(6); sweep in degrees = sweep × 180 ÷ π

    G-code and toolpath exports cam-post.js
    • PartCraft
    64-bit
  • Toolpath as JSON

    Writes the setup, tools and every operation's moves.

    JSON.stringify of the moves

    G-code and toolpath exports cam-post.js
    • PartCraft
    64-bit
  • Spindle speed and feeds

    The spindle speed, cutting feed, plunge feed and ramp feed for a tool.

    rpm = round(1000 vc ÷ (π d)), limited to the machine's range; feed = rpm × flutes × f_z; plunge = feed ÷ 3; ramp = feed ÷ 2

    Cutting speeds, feeds and tool profiles cam-tools.js
    • PartCraft
    64-bit
  • Rounding feeds to one decimal

    Rounds a feed rate to tenths.

    round1(v) = round(v × 10) ÷ 10

    Cutting speeds, feeds and tool profiles cam-tools.js
    • PartCraft
    64-bit
  • Tool tip profile

    The height of the cutting surface above the tool's tip at a given distance from its axis.

    ball: R − √(R² − ρ²); bull: r_c − √(r_c² − (ρ − a)²) beyond a = R − r_c; drill and chamfer: (ρ − r_t) ÷ tan(angle ÷ 2); flat: 0

    Cutting speeds, feeds and tool profiles cam-tools.js
    • PartCraft
    64-bit
  • Unit factors

    The factor from the file's units to millimeters.

    mm 1; cm 10; m 1000; in 25.4

    Nested sheets from DXF to toolpaths cam-sheets.js
    • PartCraft
    Exact
  • Bulged segments to arcs

    Turns a polyline with bulges into lines and true arcs.

    r = (d ÷ 2)(1 + b²) ÷ (2|b|); offset = (d ÷ 2)(1 − b²) ÷ (2b); sweep = 4 atan(b)

    Nested sheets from DXF to toolpaths cam-sheets.js
    • PartCraft
    64-bit
  • Extent of an outline

    The box round a sheet or a part outline, used for sheet size and for placing parts on sheets.

    min and max over points sampled along each piece at 0.05 chord tolerance

    Nested sheets from DXF to toolpaths cam-sheets.js
    • PartCraft
    64-bit
  • Part coordinates on its sheet

    Moves a part's points so its sheet's lower left corner is the origin, in millimeters.

    x′ = (x − sheet x₀) × k; y′ = (y − sheet y₀) × k

    Nested sheets from DXF to toolpaths cam-sheets.js
    • PartCraft
    64-bit
  • Elementary functions

    The one-argument math functions a script can call: roots, exponentials, logarithms, trigonometry, hyperbolic functions, rounding and angle conversion.

    log1p(x) = x − x² ÷ 2 + x³ ÷ 3 for |x| < 1e-4, else log(1 + x); asinh(x) = sign × log(|x| + √(x² + 1)); atanh(x) = ½ log((1 + x) ÷ (1 − x)); sind(x) = sin(x × π ÷ 180)

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Rounding to a number of decimals

    round(x, d): rounds to d decimal places.

    round(x × 10^d) ÷ 10^d

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Gamma function and factorial

    Γ(x), and factorial(n) = Γ(n + 1).

    whole x < 171: (x − 1)! by product; x < 0.5: π ÷ (sin(πx) Γ(1 − x)); else √(2π) t^(x − ½) e^(−t) Σ c_i ÷ (x − 1 + i), t = x + 6.5

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Binomial coefficient

    nchoosek(n, k): the number of ways to choose k of n.

    r ← r × (n − m + i) ÷ i for i = 1 … m, m = min(k, n − k); result = round(r)

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Spacing of numbers

    eps(x): the gap between x and the next larger 64-bit number.

    2^(floor(log₂|x|) − 52); eps(0) = 5e-324

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Evenly spaced values

    linspace(a, b, n): n values from a to b.

    value i = a + (b − a) × i ÷ (n − 1)

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Logarithmically spaced values

    logspace(a, b, n): n values from 10^a to 10^b.

    value i = 10 ^ (a + (b − a) × i ÷ (n − 1))

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Running sum and product

    cumsum and cumprod along a dimension.

    acc ← acc + x_k (or acc × x_k), stored at each step

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Variance and standard deviation

    var and std of a set of values.

    m = Σx ÷ n; var = Σ(x − m)² ÷ (n − 1), or ÷ n with weight 1; std = √var

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Median

    The middle value of a set, or the mean of the two middle values.

    sorted s; n odd: s[(n − 1) ÷ 2]; n even: (s[n ÷ 2 − 1] + s[n ÷ 2]) ÷ 2

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Dot product

    dot(a, b): the sum of products of two vectors.

    Σ a_i b_i

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Trapezoid integration

    trapz(y) or trapz(x, y): the area under sampled data.

    Σ (x_i − x_{i−1}) (y_i + y_{i−1}) ÷ 2

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • One-dimensional interpolation

    interp1(x, y, xi): linear, nearest or previous-value interpolation in a table.

    y = y_lo + (y_hi − y_lo)(q − x_lo) ÷ (x_hi − x_lo)

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Polynomial evaluation

    polyval(p, x): the value of a polynomial.

    s ← s × x + c for each coefficient (Horner)

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Polynomial fit

    polyfit(x, y, n): the least-squares polynomial of degree n through data.

    V_ij = x_i^(n − j); solve V p ≈ y

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Matrix to text

    mat2str(A): text that can be typed back in to recreate a matrix.

    each value written with toPrecision(15) by default

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Number to text

    num2str(x): a short text form of a number.

    whole numbers in full; otherwise max(ceil(log₁₀|x|), 1) + 4 significant digits

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Text to number

    str2double(s): reads a number from text.

    Number(text) for text matching a decimal pattern, else NaN

    CraftScript core math functions cs-lib-core.js
    • PartCraft
    64-bit
  • Conversion to single precision

    single(A): each value rounded to the nearest 32-bit floating-point number.

    x ← fround(x)

    CraftScript number type conversions cs-lib-core.js
    • PartCraft
    32-bit in part
  • Conversion to whole-number types

    int8, int16, int32, int64 and the unsigned forms: each value rounded to a whole number.

    x ← round(x); NaN → 0

    CraftScript number type conversions cs-lib-core.js
    • PartCraft
    64-bit
  • Read an STL file

    Reads the triangles of a binary or text STL file into a model's node coordinates.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Weld STL vertices

    Merges the repeated corners of an STL triangle list into shared nodes.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    Exact
  • Write a binary STL file

    Writes a triangle surface with a unit normal per triangle.

    n = (b − a) × (c − a) ÷ |(b − a) × (c − a)|

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Write an OBJ file

    Writes node coordinates and triangle corner numbers as text.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Read an OBJ file

    Reads vertex lines and face lines into node coordinates and triangles.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Read a CSV file

    Reads a table of numbers into a matrix.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Write a CSV file

    Writes a matrix as rows of text.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Values to JSON

    Prepares a script value for a JSON file.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Read an NPY file

    Reads a NumPy array file into a tensor.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Write an NPY file

    Writes a tensor as a NumPy array file.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Write a tensor to HDF5

    Writes a tensor as an HDF5 dataset in row-major order.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Read an HDF5 dataset

    Reads a dataset into a number, a logical value or a tensor.

    CraftScript file readers and writers cs-lib-io.js
    • PartCraft
    64-bit
  • Plot data as CSV

    Writes the x and y values of a script plot as a CSV file.

    CraftScript file readers and writers cs-plot-export.js
    • PartCraft
    64-bit
  • One CSV cell

    Turns one value into the text of a CSV cell.

    CraftScript file readers and writers cs-plot-export.js
    • PartCraft
    64-bit
  • Matrix product

    The product of two dense matrices.

    C_ij = Σ_p A_ip × B_pj

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • LU factorization

    Factors a square matrix with row exchanges.

    P A = L U

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Solve with an LU factorization

    Forward and back substitution for one or more right-hand sides.

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Cholesky factorization

    Factors a symmetric positive definite matrix as RᵀR.

    R_jj = √(A_jj − Σ_k R_kj²)

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    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.