Evaluate any multivariable equation or polynomial at compile time with high accuracy and zero runtime overhead.
Features
no_stdcompatible – no heap allocations, no panics.- Full compile-time evaluation of arbitrarily complex equations with high numerical accuracy (benchmarked at 1e-7).
- Fully documented with code examples, user-friendly macros, benchmarking, and a comprehensive suite of tests.
- Define expressions using variety of mathematical functions, all evaluable at compile time:
Identity: the variable itself (no function applied)Pow(u32): power functionx^nwherenis the exponentSin: sine functionCos: cosine functionTan: tangent functionExp: exponential function (e^x)Ln: natural logarithmSqrt: square root functionArctan: arctangent functionSinh: hyperbolic sine functionCosh: hyperbolic cosine function
Who is this for?
-
This library is primarily meant to empower scientific computing and mathematical libraries in rust to perform all numerical approximations entirely at compile time.
-
Embedded and no_std environments where heapless, panic-free code is essential.
-
Metaprogramming and symbolic math tools that benefit from evaluating complex expressions entirely at compile time.
Examples
Simple Sine Polynomial (1 variable, 1 term):
use ;
use Sin;
const POLY_1V_1T: = const_poly!;
const VARS: = ; // sin(1.2) ≈ 0.932039
const RESULT: f64 = POLY_1V_1T.evaluate; // ≈ 1.864078
Mixed Trigonometric Polynomial (2 Variables, 2 terms):
use ;
use ;
const POLY_2V_2T: = const_poly!;
const VARS: = ;
const RESULT: f64 = POLY_2V_2T.evaluate; // ~ 0.7705881
Powers with Mixed Exponents (3 Variables, 5 terms):
use ;
use Pow;
const POLY_3V_5T: = const_poly!;
const VARS: = ;
const RESULT: f64 = POLY_3V_5T.evaluate; //~ -30.159027778
Powers with mixed exponents, trignometric and log functions (4 variables, 4 terms):
use ;
use *;
const POLY_4V_4T: = const_poly!;
const VARS = ;
const RESULT = POLY_4V_4T.evaluate; // ~ -112.280027300776
Benchmarks
See BENCHMARKS.md
Contributions Guide
See CONTRIBUTIONS.md
LICENSE
const_poly is licensed under the MIT license.
Contact
If you use this library in your project, a shoutout or mention would be awesome!
TODO
-
Add polynomial operations like add/subtract/multiply.
-
Add more benchmarking.