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

  • 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
  • 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
  • Preconditioned conjugate gradients

    Solves a symmetric positive definite sparse system with the pcg builtin.

    CraftScript iterative solvers and sparse eigenvalues cs-lib-linalg.js
    • PartCraft
    64-bit
  • Jacobi preconditioner

    Scales a residual by the inverse of the matrix diagonal.

    zᵢ = rᵢ ÷ A_ii

    CraftScript iterative solvers and sparse eigenvalues cs-lib-linalg.js
    • PartCraft
    64-bit
  • Incomplete LU factorization

    The ILU(0) preconditioner used by BiCGSTAB.

    CraftScript iterative solvers and sparse eigenvalues cs-lib-linalg.js
    • PartCraft
    64-bit
  • BiCGSTAB

    Solves a general sparse system by iteration.

    stop when ‖r‖ ÷ ‖b‖ < tol

    CraftScript iterative solvers and sparse eigenvalues cs-lib-linalg.js
    • PartCraft
    64-bit
  • Rigid-body vectors for AMG

    Builds the translation and rotation vectors the multigrid preconditioner uses.

    rotation about the centroid: (−(y − c_y), x − c_x)

    CraftScript iterative solvers and sparse eigenvalues cs-lib-linalg.js
    • PartCraft
    64-bit
  • Smallest eigenvalues of a sparse problem

    The k smallest eigenvalues and vectors of K v = λ M v.

    stop when |λⱼ − λⱼ(previous)| ≤ tol × |λⱼ| for every j ≤ k

    CraftScript iterative solvers and sparse eigenvalues cs-lib-linalg.js
    • PartCraft
    64-bit
  • Unit factors

    The factors that turn the given force, length and torque units into newtons, millimeters and newton millimeters.

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Arguments to working units

    Converts the given force, lengths and torque to N, mm and N·mm.

    value × unit factor

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Rounding to stock sizes and to reported decimals

    Rounds a thickness up to a stock plate or a 0.5 mm step, and rounds reported values.

    r2(v) = round(100 v) ÷ 100; r3(v) = round(1000 v) ÷ 1000

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Bolt positions in the flange

    The heights of the two bolts and the flange height.

    y_b = t + 1.5 × hole; spacing = clamp(round(a ÷ 10) × 5, 30, 100); H = y_t + 1.5 × hole

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Bracket checks

    Bending and shear stress, tip deflection and bolt loads of the bracket, each with its limit and safety factor.

    σ = 6 F a ÷ (b t²); τ = 1.5 F ÷ (b t); δ = F a³ ÷ (3 E I), I = b t³ ÷ 12; T = M y₂ ÷ (y₁² + y₂²); (T ÷ T_all)² + (V ÷ V_all)² ≤ 1

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Bracket sizing, volume and mass

    The thickness for strength and for the deflection limit, the bolt size, and the bracket's volume and mass.

    t = √(6 M ÷ (b σ_allow)); t = ∛(4 F a³ ÷ (E b δ)); V = b (L t + (H − t) t) − 2 (π ÷ 4) hole² t; mass = V × density × 1e-6

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Shaft checks

    Von Mises stress, torsional shear and twist of a round shaft.

    σ' = 32 ÷ (π d³) × √(M² + ¾T²); τ = 16 T ÷ (π d³); θ = T L ÷ (G J), G = E ÷ (2(1 + ν)), J = π d⁴ ÷ 32

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Shaft sizing, volume and mass

    The required diameter, the standard size above it, and the shaft's volume and mass.

    d = ∛(32 SF √(M² + ¾T²) ÷ (π S_y)); V = (π ÷ 4) d² L

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • The built part

    Sketches and extrudes the sized bracket or shaft as part features.

    density (g/cm³) = density (kg/m³) ÷ 1000

    Design-it sizing and hand checks design-it.js
    • PartCraft
    64-bit
  • Edges and facet normals

    Finds the mesh's edges, each facet's unit normal, and which edges are sharp.

    sharp when n₁ · n₂ < cos 20°

    Drawing sheet views, dimensions and PDF drawing.js
    • PartCraft
    64-bit
  • One projected view with hidden lines

    Projects the mesh onto a view plane, finds the view's extents, and splits each drawn edge into visible and hidden parts.

    (u, v, w) = (p · right, p · up, p · dir)

    Drawing sheet views, dimensions and PDF drawing.js
    • PartCraft
    64-bit
  • Merging collinear segments

    Joins touching or overlapping segments on the same line and removes hidden lines under visible ones.

    Drawing sheet views, dimensions and PDF drawing.js
    • PartCraft
    64-bit
  • Section hatching

    Hatch lines at an angle inside the cut outline.

    Drawing sheet views, dimensions and PDF drawing.js
    • PartCraft
    64-bit
  • Clip to the detail circle

    Keeps the parts of segments inside the detail view's circle.

    A t² + B t + C = 0; t = (−B ± √(B² − 4AC)) ÷ 2A

    Drawing sheet views, dimensions and PDF drawing.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.