Function polyeval::horner

source ·
pub fn horner<T>(x: T, coeffs: &[T]) -> T
where T: Zero + for<'a> Add<&'a T, Output = T> + for<'a> Mul<&'a T, Output = T>,
Expand description

Evaluate a polynomial with Horner’s method.

The coefficients are listed from zeroth order to highest.

§Examples

use polyeval::horner;

let x = 7;

assert_eq!(horner(x, &[]), 0);
assert_eq!(horner(x, &[0]), 0);

assert_eq!(
    horner(x, &[2, 3, 4]),
    2 + x * (3 + x * 4)
);