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.
This commit is contained in:
aherbert 2022-07-15 17:28:33 +01:00
parent 64e2818924
commit 0bf33a4fc1
1 changed files with 2 additions and 1 deletions

View File

@ -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);