From 0bf33a4fc13474835414a24c80d50cc7710eaf49 Mon Sep 17 00:00:00 2001 From: aherbert Date: Fri, 15 Jul 2022 17:28:33 +0100 Subject: [PATCH] Use Complex.ZERO. This does not change the equals comparison. Note that this will not detect sign differences, e.g. (0.0, 0.0) == (-0.0, 0.0) and a tolerance may be required for more robustness. --- .../commons/math4/legacy/analysis/solvers/LaguerreSolver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java index e0dcc37b7..24afe0b7f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java @@ -368,7 +368,8 @@ public class LaguerreSolver extends AbstractPolynomialSolver { final Complex denominator = dplus.abs() > dminus.abs() ? dplus : dminus; // Perturb z if denominator is zero, for instance, // p(x) = x^3 + 1, z = 0. - if (denominator.equals(Complex.ofCartesian(0.0, 0.0))) { + // This uses exact equality to zero. A tolerance may be required here. + if (denominator.equals(Complex.ZERO)) { z = z.add(Complex.ofCartesian(absoluteAccuracy, absoluteAccuracy)); oldz = Complex.ofCartesian(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);