From f2970819a26bcc5370c88838c740d507583d9184 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 15 Feb 2019 09:39:25 +0100 Subject: bug #1679: avoid possible division by 0 in complex-schur --- Eigen/src/Eigenvalues/ComplexSchur.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Eigen/src/Eigenvalues') diff --git a/Eigen/src/Eigenvalues/ComplexSchur.h b/Eigen/src/Eigenvalues/ComplexSchur.h index b8b3490c6..fc71468f8 100644 --- a/Eigen/src/Eigenvalues/ComplexSchur.h +++ b/Eigen/src/Eigenvalues/ComplexSchur.h @@ -300,10 +300,13 @@ typename ComplexSchur::ComplexScalar ComplexSchur::compu ComplexScalar trace = t.coeff(0,0) + t.coeff(1,1); ComplexScalar eival1 = (trace + disc) / RealScalar(2); ComplexScalar eival2 = (trace - disc) / RealScalar(2); - - if(numext::norm1(eival1) > numext::norm1(eival2)) + RealScalar eival1_norm = numext::norm1(eival1); + RealScalar eival2_norm = numext::norm1(eival2); + // A division by zero can only occur if eival1==eival2==0. + // In this case, det==0, and all we have to do is checking that eival2_norm!=0 + if(eival1_norm > eival2_norm) eival2 = det / eival1; - else + else if(eival2_norm!=RealScalar(0)) eival1 = det / eival2; // choose the eigenvalue closest to the bottom entry of the diagonal -- cgit v1.2.3