From 99a7de0a7b3461ed32358480937c607523eafeda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20S=C3=B6rng=C3=A5rd?= <44257381+JSorngard@users.noreply.github.com> Date: Sat, 19 Sep 2026 18:17:57 +0200 Subject: [PATCH] Revert "Simplify polynomial function (#346)" This reverts commit ac1e32ef14aa1c816a0a7601db0b2b25a3efd172. --- CHANGELOG.md | 4 ---- src/generic_math.rs | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adc4d50..9986faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,6 @@ 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 6182b14..2226792 100644 --- a/src/generic_math.rs +++ b/src/generic_math.rs @@ -40,10 +40,12 @@ pub(crate) fn rational_function( #[inline] fn polynomial(x: T, coefficients: [T; N]) -> T { coefficients - .into_iter() + .iter() .rev() - .reduce(|acc, coefficient| acc * x + coefficient) - .unwrap_or(T::zero()) + .skip(1) + .fold(*coefficients.last().unwrap_or(&T::zero()), |acc, &c| { + acc * x + c + }) } // The functions below are wrappers around the [`num-traits`] crate,