numx


A portable, scientific-grade numerical computing library in pure C99 for resource-constrained embedded systems.
Why numx
Most numerical libraries assume a heap, an OS, and a math coprocessor. numx assumes none of those things. It targets the processors where computation is hardest: ESP32, ARM Cortex-M/A, AVR, RISC-V — and it brings algorithms previously considered out of reach (automatic differentiation, compressed sensing, post-quantum NTT) to those platforms.
Every function is reentrant, allocation-free, and returns a typed status code. The entire precision of the library — float32 or float64 — is switchable with a single compile flag.
Module status
| Module |
Functions |
Status |
| linalg |
dot, norm, cross, mat_mul, transpose, det, LU |
✅ complete |
| stats |
mean, variance, median, percentile |
✅ complete |
| roots |
bisect, newton, brent |
✅ complete |
| integrate |
trap, simpson, gauss |
✅ complete |
| differentiate |
forward, central, richardson |
✅ complete |
| interpolate |
linear, cubic spline, chebyshev |
✅ complete |
| poly |
eval (Horner), roots (Newton + deflation) |
✅ complete |
| ode |
rk4, rk45 (adaptive) |
✅ complete |
| signal |
windows, FIR, IIR, convolve, correlate, peaks, EMA |
✅ complete |
| fft |
Cooley-Tukey f32, Q15, IFFT, magnitude |
✅ complete |
| autodiff |
forward-mode (dual numbers), reverse-mode (static tape) |
✅ complete |
| compressed_sensing |
OMP, ISTA |
✅ complete |
| sketch |
randomized SVD (Halko-Martinsson-Tropp) |
✅ complete |
| ntt |
Number Theoretic Transform (Kyber/Dilithium params) |
✅ complete |
Hardware validation
All results are device-run, per-formula values with measured error margins — not simulation. Full tables: validation/results/.
| Platform |
Toolchain |
Modules |
Tests |
| x86-64 — Intel i7-13700H / Ubuntu 22.04 |
gcc 11.4.0 -O2 / float32 |
13 / 14 ¹ |
300 / 300 ✅ |
| ARM64 — Apple M4 Pro / macOS 26.2–26.5.1 |
Apple clang 21.0.0 -O2 / float32 |
14 / 14 |
329 / 329 ✅ |
| ARM64 — Apple M1 Pro / macOS 26.2 |
Apple clang 17.0.0 -O2 / float32 |
13 / 14 ¹ |
300 / 300 ✅ |
| Windows x64 — MSVC 14.51 (VS 2026 Build Tools) |
MSVC /O2 / float32 |
13 / 14 ¹ |
295 / 295 ✅ |
| Windows x64 — MSVC 14.51 (VS 2026 Build Tools) |
MSVC /O2 / float64 |
14 / 14 |
329 / 329 ✅ ³ |
| Windows x86 (32-bit, i386) — MSVC 19.51.36246.0 |
MSVC /O2 / float32 |
14 / 14 |
329 / 329 ✅ |
| Linux x86-64 — WSL2 Ubuntu 24.04 |
gcc 13.3.0 -O2 / float64 |
14 / 14 |
329 / 329 ✅ |
| Linux x86 (32-bit) — WSL2 Ubuntu 24.04 |
gcc 13.3.0 -m32 -O2 / float32 |
14 / 14 |
329 / 329 ✅ |
| ESP32-S3 — Xtensa LX7 / ESP-IDF v5.5.2 |
xtensa-esp32s3-elf-gcc -O2 / float32 |
14 / 14 ² |
577 / 579 ✅ |
| ARM64 — Raspberry Pi 4B / Raspbian GNU/Linux 13 |
gcc 14.2.0 -O2 / float32 |
14 / 14 |
329 / 329 ✅ |
ESP32-S3: 2 sketch test cases fail due to rand() seed portability across libc implementations — the RSVD algorithm is correct; the test fixture is not portable. See FLAG S-01 in validation/results/sketch/sketch.md.
¹ NTT not validated on this exact platform/toolchain combination; validated separately on Windows x86 (32-bit) and Linux x86/x86-64 via WSL2 instead. See validation/results/ntt/ntt.md.
² ESP32-S3 NTT results (29/29) were collected via a standalone example project (examples/esp32_ntt_test/), not the tests/esp32_tests/ harness used for the other 13 modules — the two don’t share a single test binary, so this row sums both (548+29 pass / 550+29 total).
³ Confirmed by Amir re-running this exact build (NUMX_USE_DOUBLE) on 2026-07-03: 329/329. The earlier 294/294 baseline for this config (2026-06-06) was stale — the non-NTT test count on this platform had grown to 300 sometime after that run, independent of NTT, matching the 300-test baseline on every other current platform (300+29=329).
Quick start
Option A — FetchContent (recommended)
include(FetchContent)
FetchContent_Declare(numx
GIT_REPOSITORY https://github.com/NIKX-Tech/numx.git
GIT_TAG v1.0.0
)
FetchContent_MakeAvailable(numx)
target_link_libraries(my_target PRIVATE numx::numx)
Option B — clone and build locally
git clone https://github.com/NIKX-Tech/numx.git
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure
Switch to double precision:
cmake -B build -DCMAKE_BUILD_TYPE=Release -DNUMX_USE_DOUBLE=1
Option C — standalone platform test builds
Self-contained CMake projects for per-platform float32/float64 validation:
# float32 Unity tests (x86)
cmake -S tests/x86 -B tests/x86/build && cmake --build tests/x86/build
# float64 Unity tests (x64)
cmake -S tests/x64 -B tests/x64/build && cmake --build tests/x64/build
For ESP32: see tests/esp32_tests/CMakeLists.txt (IDF component).
Usage example
#include "numx/numx.h"
int main(void) {
/* Switch precision via -DNUMX_USE_DOUBLE at compile time. */
/* All functions return numx_status_t — always check it. */
numx_real_t result;
numx_status_t s = numx_integrate_simpson(my_func, 0.0f, 1.0f, 100, &result);
if (s != NUMX_OK) {
/* handle error */
return 1;
}
return 0;
}
Benchmarks
Per-call averages measured on physical hardware. Full tables: validation/results/. Platform-specific benchmark runners: benchmarks/bench_runner.c (Linux/macOS), benchmarks/bench_win.c (Windows), benchmarks/esp32/ (ESP32 Phase 1 & 2).
| Function |
x86-64 (gcc -O2) |
RPi 4B / ARM64 (gcc -O2) |
ESP32-S3 (240 MHz) |
numx_vec_dot n=64 |
15 ns |
15 ns ¹ |
5.5 µs |
numx_mat_mul 4×4 |
26 ns |
62 ns ¹ |
11 µs |
numx_lu_decompose 4×4 |
29 ns |
300 ns |
10 µs |
numx_integrate_gauss npts=8 |
11 ns |
22 ns ¹ |
2.7 µs |
numx_root_brent tol=1e-6 |
103 ns |
949 ns |
20 µs |
numx_ode_rk45 tol=1e-4 |
239 ns |
1,337 ns |
40 µs |
numx_stats_median n=128 |
6.6 µs |
204 ns ¹ |
1.1 ms |
numx_fft_f32 N=64 |
3.6 µs |
17.9 µs |
2.6 ms |
numx_autodiff fwd chain-10 |
20 ns |
102 ns |
358 ns |
numx_ntt_forward n=256 |
1.9 µs ² |
26.6 µs |
767 µs |
numx_ntt_inverse n=256 |
1.1 µs ² |
22.0 µs |
673 µs |
numx_ntt_polymul n=256 |
5.3 µs ² |
81.3 µs |
2.4 ms |
numx_ntt_poly_add n=256 |
121 ns ² |
2.4 µs |
72.3 µs |
¹ RPi benchmark used smaller inputs (n=4, 2×2, npts=2, n=8 respectively) — see validation/hardware/raspberry_pi.md for exact parameters.
² NTT x86-64 column measured on WSL2 Ubuntu 24.04 / gcc 13.3.0 (not the native Ubuntu 22.04 / gcc 11.4 host used for the other rows) — see validation/results/ntt/ntt.md. NTT operates on fixed-point numx_q15_t, unaffected by the float32/float64 build flag.
Contributing
See CONTRIBUTING.md for the rules, templates, and the exact
prompt pattern to use with Claude Code when adding a new algorithm.
License
MIT — see LICENSE.
Citation
Once the accompanying paper is published, cite as:
@software{numx2026,
author = {NIKX Technologies},
title = {numx: Scientific Numerical Computing for Embedded Systems},
year = {2026},
url = {https://github.com/NIKX-Tech/numx},
license = {MIT}
}
评论