bug #1679: avoid possible division by 0 in complex-schur

This commit is contained in:
Gael Guennebaud 2019-02-15 09:39:25 +01:00
parent 65e23ca7e9
commit f2970819a2

View File

@ -300,10 +300,13 @@ typename ComplexSchur<MatrixType>::ComplexScalar ComplexSchur<MatrixType>::compu
ComplexScalar trace = t.coeff(0,0) + t.coeff(1,1); ComplexScalar trace = t.coeff(0,0) + t.coeff(1,1);
ComplexScalar eival1 = (trace + disc) / RealScalar(2); ComplexScalar eival1 = (trace + disc) / RealScalar(2);
ComplexScalar eival2 = (trace - disc) / RealScalar(2); ComplexScalar eival2 = (trace - disc) / RealScalar(2);
RealScalar eival1_norm = numext::norm1(eival1);
if(numext::norm1(eival1) > numext::norm1(eival2)) 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; eival2 = det / eival1;
else else if(eival2_norm!=RealScalar(0))
eival1 = det / eival2; eival1 = det / eival2;
// choose the eigenvalue closest to the bottom entry of the diagonal // choose the eigenvalue closest to the bottom entry of the diagonal