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 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
  • Solve with a Cholesky factorization

    Solves RᵀR X = B by two triangular substitutions.

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

    Factors a matrix as an orthogonal matrix times an upper triangular one.

    H = I − β v vᵀ, β = 2 ÷ (vᵀv)

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Symmetric eigenvalues and vectors

    All eigenvalues, and optionally eigenvectors, of a symmetric matrix, in ascending order.

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Generalized symmetric eigenproblem

    Eigenvalues and vectors of K v = λ M v for symmetric K and positive definite M.

    M = RᵀR; C = R⁻ᵀ K R⁻¹; C y = λ y; v = R⁻¹ y

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Choice of solver for A x = b

    Picks the method for the backslash operator and linsolve, for dense and sparse matrices.

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Matrix inverse

    The inverse of a square matrix.

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

    The determinant of a square matrix.

    det A = sign × Π U_ii

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Vector and matrix norms

    The 1, 2, infinity, p and Frobenius norms.

    ‖x‖₂ = √(Σ xᵢ²); ‖A‖₂ = √(λ_max(AᵀA))

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Condition number

    The 2-norm condition number of a matrix.

    cond A = √(λ_max(AᵀA) ÷ λ_min(AᵀA))

    CraftScript dense linear algebra cs-lib-linalg.js
    • PartCraft
    64-bit
  • Sparse matrix from triplets

    Builds a sparse matrix from row, column and value lists, adding values that share a place.

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Weighted sum of two sparse matrices

    a·A + b·B for matrices of the same size.

    C_ij = a × A_ij + b × B_ij

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Sparse matrix times vector

    The product of a sparse matrix and a vector.

    y_r = Σ_k val_k × x_col(k)

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Sparse matrix times sparse matrix

    The product of two sparse matrices.

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Symmetry test

    Decides whether a sparse matrix is symmetric, which selects the solver.

    max |S − Sᵀ| ≤ 1e-10 × max |S|

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Envelope size after reordering

    Counts the stored entries and the work of the skyline factorization for an ordering.

    entries = Σ wᵢ; work = Σ wᵢ² ÷ 2, wᵢ = i − firstᵢ + 1

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Envelope Cholesky factorization and solve

    Factors a symmetric positive definite sparse matrix and solves with the factor.

    L_ij = (A_ij − Σ_k L_ik L_jk) ÷ L_jj; L_ii = √(A_ii − Σ_k L_ik²)

    CraftScript sparse matrices and direct factorization cs-lib-linalg.js
    • PartCraft
    64-bit
  • Assembly of element matrices

    Adds weighted element matrices into one sparse matrix.

    K = Σ_e w_e × P_eᵀ Ke P_e

    CraftScript sparse matrices and direct factorization cs-lib-linalg.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
  • One operator on two numbers

    Adds, subtracts, multiplies, divides, compares or takes the remainder of two numbers.

    mod(x, y) = x − ⌊x ÷ y⌋ × y; rem(x, y) = x − trunc(x ÷ y) × y

    CraftScript array arithmetic cs-tensor.js
    • PartCraft
    64-bit
  • Hypotenuse

    √(x² + y²) for two numbers.

    m × √((x ÷ m)² + (y ÷ m)²), m = max(|x|, |y|)

    CraftScript array arithmetic cs-tensor.js
    • PartCraft
    64-bit
  • Power

    x raised to the power y.

    CraftScript array arithmetic cs-tensor.js
    • PartCraft
    64-bit
  • Elementwise loops

    Applies an operator to every element of one or two arrays.

    CraftScript array arithmetic cs-tensor.js
    • PartCraft
    64-bit
  • Matrix product

    The product of two dense matrices in a script expression.

    C_ij = Σ_p A_ip × B_pj

    CraftScript array arithmetic cs-tensor.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.