| Crates.io | exp-rs |
| lib.rs | exp-rs |
| version | 0.2.0 |
| created_at | 2025-04-21 02:41:58.724861+00 |
| updated_at | 2025-12-16 20:44:02.550674+00 |
| description | no_std expression parser, compiler, and evaluation engine for math expressions designed for embedded, with qemu examples |
| homepage | https://github.com/cosmikwolf/exp-rs |
| repository | https://github.com/cosmikwolf/exp-rs |
| max_upload_size | |
| id | 1642215 |
| size | 4,552,674 |
A tiny, no_std Pratt expression parser and evaluator for embedded systems.
[dependencies]
exp-rs = "0.2"
By default, exp-rs uses 64-bit floating point (double precision) for calculations. You can configure the precision using feature flags:
# Use default 64-bit precision (double)
exp-rs = "0.2"
# Use 32-bit precision (float)
exp-rs = { version = "0.2", features = ["f32"] }
The f64 mode is the default when f32 is not specified.
For embedded systems, you can disable the libm dependency to reduce binary size and provide your own math function implementations:
# Disable libm dependency
exp-rs = { version = "0.2", default-features = false }
use exp_rs::Expression;
use bumpalo::Bump;
let arena = Bump::new();
let result = Expression::eval_simple("2 + 3 * 4", &arena).unwrap();
assert_eq!(result, 14.0);
For the full API including parameters, batch evaluation, custom functions, and more, see the documentation.
A C header is automatically generated during build via cbindgen:
#include "exp_rs.h"
int main() {
double result = exp_rs_eval("2+2*2");
printf("%f\n", result); // prints "6.000000"
return 0;
}
The header is generated at include/exp_rs.h after running cargo build.
cargo build
cargo test
meson setup build
meson compile -C build
# Run QEMU embedded tests
./run_tests.sh --qemu -v
# Run with allocation tracking
./run_tests.sh --qemu -a system --track-allocs -v -c
# Run native C tests
./run_tests.sh --native -v
# See all options
./run_tests.sh --help
cargo install cargo-tarpaulin
cargo tarpaulin --workspace
exp-rs began as a fork of tinyexpr-rs by Krzysztof Kondrak, which was a port of TinyExpr by Lewis Van Winkle. The grammar is based on tinyexpr-plusplus by Blake Madden.
Key differences from tinyexpr:
Licensed under either of