gifnksm / polynomial-rs

Manipulations and data types that represent polynomial
MIT License
16 stars 10 forks source link

Ideas for const polynomials? #18

Open jkelleyrtp opened 2 years ago

jkelleyrtp commented 2 years ago

Right now polynomial requires a Vec. It would be useful to have either a smallvec or a fixed array to avoid heap allocations.

This would let me write a library that exports polynomials as constants. IE the first complete elliptic integral for use in high-performance simulations.

Any of [T; N] or &'static T would be useful.

gifnksm commented 2 years ago

Does your use case require const? If you need pre-defined global variables, static variables are sufficient. For example, using once_cell, you can define immutable global variables in the current polynomial as follows.

use once_cell::sync::Lazy;
use polynomial::Polynomial;

static POLYNOMIAL: Lazy<Polynomial<i32>> = Lazy::new(|| {
    Polynomial::new(vec![1, 2, 3])
});

fn main() {
    println!("{}", POLYNOMIAL.pretty("x"));
}