diff --git a/CHANGELOG.md b/CHANGELOG.md index 9986faf..adc4d50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This file contains the changes to the crate since version 0.1.1. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +- Use `reduce` instead of `fold` in the polynomial evaluation function. + ## [2.0.5] - 2026-09-18 - Speed up the Lambert W functions that use Fukushima's method slightly (by up to 10 percent) diff --git a/src/generic_math.rs b/src/generic_math.rs index 2226792..6182b14 100644 --- a/src/generic_math.rs +++ b/src/generic_math.rs @@ -40,12 +40,10 @@ pub(crate) fn rational_function( #[inline] fn polynomial(x: T, coefficients: [T; N]) -> T { coefficients - .iter() + .into_iter() .rev() - .skip(1) - .fold(*coefficients.last().unwrap_or(&T::zero()), |acc, &c| { - acc * x + c - }) + .reduce(|acc, coefficient| acc * x + coefficient) + .unwrap_or(T::zero()) } // The functions below are wrappers around the [`num-traits`] crate,