From 66819df2547cacd22be2747073704efae04097b9 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:21:33 +0200 Subject: [PATCH] Revert "Revert "Simplify polynomial function (#346)" (#348)" This reverts commit 002a9c3236bd4c96a8604ea72f9f9d72481c52a9. --- CHANGELOG.md | 4 ++++ src/generic_math.rs | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) 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,