From 9044c98cff257a4f7429deaa78cae59132957db7 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 19 Oct 2010 21:56:11 -0400 Subject: [PATCH] work around stupid msvc error when constructing at compile time an expression that involves a division by zero, even if the numeric type has floating point --- Eigen/src/SVD/JacobiSVD.h | 3 +++ test/jacobisvd.cpp | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index f3b0ccce4..44880dcf4 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -239,6 +239,9 @@ struct ei_qr_preconditioner_impl +EIGEN_DONT_INLINE Scalar zero() { return Scalar(0); } + template void jacobisvd_inf_nan() { + // all this function does is verify we don't iterate infinitely on nan/inf values + JacobiSVD svd; typedef typename MatrixType::Scalar Scalar; - Scalar some_inf = Scalar(1) / Scalar(0); + Scalar some_inf = Scalar(1) / zero(); + VERIFY((some_inf - some_inf) != (some_inf - some_inf)); svd.compute(MatrixType::Constant(10,10,some_inf), ComputeFullU | ComputeFullV); - Scalar some_nan = Scalar(0) / Scalar(0); + + Scalar some_nan = zero() / zero(); + VERIFY(some_nan != some_nan); svd.compute(MatrixType::Constant(10,10,some_nan), ComputeFullU | ComputeFullV); + MatrixType m = MatrixType::Zero(10,10); m(ei_random(0,9), ei_random(0,9)) = some_inf; svd.compute(m, ComputeFullU | ComputeFullV); + m = MatrixType::Zero(10,10); m(ei_random(0,9), ei_random(0,9)) = some_nan; svd.compute(m, ComputeFullU | ComputeFullV);