Skip to main content

NumCore

Launch NumCore Simulator
Run the full firmware math engine in your browser
No download required · 429 KB · Works offline

Note: The simulator may not function correctly on mobile devices — for the best experience, use a PC.

Bare-metal scientific calculator firmware for the LM3S811 ARM Cortex-M3 (64 KB Flash, 8 KB SRAM), written in Rust with #![no_std] #![no_main].

Features a Q31.32 fixed-point math engine with CORDIC + Taylor-corrected trig, minimax polynomial exp/log, CLZ-based square root, rational minimax arctangent, Smith's robust complex division, Stirling's log-gamma, overflow-aware scientific notation, adaptive Simpson integration, matrix operations up to 4x4, and a bytecode VM evaluator with zero C stack growth. No heap, no allocator, no OS.

Build Status

Project highlights

  • Bytecode VM evaluation — recursive-descent compiler emits opcodes into a 256 B buffer; flat execute() loop with 16-entry value stack eliminates all C recursion. Expressions like 1+1+1+1+1+1+1+1+1+1 work correctly (the previous recursive evaluator overflowed at depth 4, silently corrupting .bss).
  • Q31.32 fixed-point — i64 storage, i128 intermediates, saturating arithmetic, EvalResult error model (Value / Overflow / DomainError), precision of 2322.33×10102^{-32}\approx2.33\times10^{-10} (~9 decimal digits)
  • CORDIC sin/cos — 22 iterations + first-order Taylor correction on residual angle (δ<221|\delta|<2^{-21}, corrected to O(δ2)<2.3×1013O(\delta^2)<2.3\times10^{-13})
  • Rational minimax atanatan(r)=rP(r2)/Q(r2)\operatorname{atan}(r)=r\cdot P(r^2)/Q(r^2), Ganssle-Homer form, Horner evaluation, error <1.6×1010<1.6\times10^{-10} rad
  • Minimax exp — degree-7 polynomial, max error 5.95×1011\sim5.95\times10^{-11}
  • Minimax ln — degree-10 polynomial, max error 1.62×109\sim1.62\times10^{-9}
  • CLZ reciprocal sqrt — 32-entry LUT + 3 Newton iterations on 1/x1/\sqrt{x}
    • 1 final Newton refinement on x\sqrt{x}
  • Smith's complex division — overflow-safe branch on cd|c|\ge|d|, handles values up to 109\sim10^9 in Q31.32
  • Stirling's ln gamma — asymptotic series z5z\ge5 with recurrence and reflection formula, 6\sim6 ULP worst-case error
  • Adaptive Simpson integration — iterative bisection, τ108\tau\approx10^{-8}, max depth 20; integrates 010sinhxdx\int_0^{10}\sinh x\,dx accurate to <2×106<2\times10^{-6}
  • Overflow-aware scientific notation — results exceeding Q31.32 range display as 1.34406E+43; binary operations adjust the overflow estimate
  • Bytecode compiler — same recursive-descent grammar, emits opcodes instead of AST nodes; 12 opcodes, 256 B fixed-size buffer
  • Complex numbers — full arithmetic + analytic-continuation trig
  • Matrix operations — 4x4 max, determinant, inverse, transpose, cofactor, adjugate, scalar broadcast, matrix multiplication
  • Scientific notation mode1.5E+10 syntax, ±99 exponent hard limit, auto-conversion to Scalar when value fits Q31.32 exactly
  • Log-space distributions — ln_gamma (Stirling), ln_factorial (hybrid table/Stirling), binomial/Poisson PMF, chi-squared CDF
  • 300/300 host-side tests pass, 6 pre-existing ignored (overflow/underflow at Q31.32 boundaries)

Supported functions

Arithmetic: + - * / ^ %. Trigonometric: sin cos tan asin acos atan. Hyperbolic: sinh cosh tanh asinh acosh atanh. Other: sqrt abs exp ln log log2 floor ceil round deg rad nthroot lngamma. Distributions: binompp poissonp chicdf. Loops: sum int. Matrix: det transpose identity inv cofactor adjugate. Storage: sto. Constants: pi e. Variables: Ans A-Z (scalar), MatA MatB MatC (matrix).

See Math Engine for full reference.

Modes

ModeScopeKey features
StandardArithmetic + transcendentalsAll functions, real numbers only
AdvancedStandard + complexImaginary unit i, complex arithmetic
MatrixStandard + matrix opsMatrix literals [(a,b)(c,d)], 4x4 limit
ScientificStandard + E-notation1.5E+10 literal syntax, exponent arithmetic

Cycle modes with Esc key.

Firmware metrics

MetricValueBudgetUsage
Flash (.text + .data)63,029 B64 KB96.2%
SRAM (.data + .bss + .stack)4,312 B8 KB52.6%

Quick start

# Build firmware (release, size-optimised)
cargo build -p numcore-lm3s811 --release --target thumbv7m-none-eabi

# Run host-side unit tests (300 tests)
cargo test -p numcore_math --tests

# Run in QEMU
qemu-system-arm -M lm3s811evb -serial mon:stdio -display none \
-kernel target/thumbv7m-none-eabi/release/NumCore

# Pipe expression
echo "2+2" | timeout 5 qemu-system-arm -M lm3s811evb -serial stdio -display none \
-kernel target/thumbv7m-none-eabi/release/NumCore

Source code: github.com/NumCore/NumCore