NumCore
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.
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 like1+1+1+1+1+1+1+1+1+1work correctly (the previous recursive evaluator overflowed at depth 4, silently corrupting.bss). - Q31.32 fixed-point — i64 storage, i128 intermediates, saturating
arithmetic,
EvalResulterror model (Value/Overflow/DomainError), precision of (~9 decimal digits) - CORDIC sin/cos — 22 iterations + first-order Taylor correction on residual angle (, corrected to )
- Rational minimax atan — , Ganssle-Homer form, Horner evaluation, error rad
- Minimax exp — degree-7 polynomial, max error
- Minimax ln — degree-10 polynomial, max error
- CLZ reciprocal sqrt — 32-entry LUT + 3 Newton iterations on
- 1 final Newton refinement on
- Smith's complex division — overflow-safe branch on , handles values up to in Q31.32
- Stirling's ln gamma — asymptotic series with recurrence and reflection formula, ULP worst-case error
- Adaptive Simpson integration — iterative bisection, , max depth 20; integrates accurate to
- 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 mode —
1.5E+10syntax, ±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
| Mode | Scope | Key features |
|---|---|---|
| Standard | Arithmetic + transcendentals | All functions, real numbers only |
| Advanced | Standard + complex | Imaginary unit i, complex arithmetic |
| Matrix | Standard + matrix ops | Matrix literals [(a,b)(c,d)], 4x4 limit |
| Scientific | Standard + E-notation | 1.5E+10 literal syntax, exponent arithmetic |
Cycle modes with Esc key.
Firmware metrics
| Metric | Value | Budget | Usage |
|---|---|---|---|
| Flash (.text + .data) | 63,029 B | 64 KB | 96.2% |
| SRAM (.data + .bss + .stack) | 4,312 B | 8 KB | 52.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