From 7494bb7710b13542057fc41885d86fe60790f28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20S=C3=B6rng=C3=A5rd?= Date: Sat, 19 Sep 2026 17:24:22 +0200 Subject: [PATCH 1/2] Use `reduce` instead of `fold` to simplify the polynomial function --- src/generic_math.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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, From b3d053185db623a56cd172fcda31c16800dfb6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20S=C3=B6rng=C3=A5rd?= Date: Sat, 19 Sep 2026 17:25:16 +0200 Subject: [PATCH 2/2] Add change to log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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)