diff --git a/src/algorithm/factorization/faust_palm4msa2020.h b/src/algorithm/factorization/faust_palm4msa2020.h
index 86ce93f6dfa80b680f1e79b994128a6e44171263..cc3807aec4853fa32f1df29284ad7a256604195e 100644
--- a/src/algorithm/factorization/faust_palm4msa2020.h
+++ b/src/algorithm/factorization/faust_palm4msa2020.h
@@ -22,6 +22,7 @@
 #include "faust_MHTP.h"
 #include <functional>
 #include <cstdlib>
+#include <cmath>
 
 #define PALM4MSA2020_VERBOSE_CALC_ERR_ITE_PERIOD 1 // the period according to the relative error is computed and displayed in palm4msa2
 // this constant is overriden if the variable environment VERBOSE_CALC_ERR_ITE_PERIOD exists
diff --git a/src/algorithm/factorization/faust_palm4msa2020_2.hpp b/src/algorithm/factorization/faust_palm4msa2020_2.hpp
index 71e26d842d9b5d86d2d0fdde883d0922a40ab9d1..dea98950ac105fc0d719a8f33c97f28396b9af0a 100644
--- a/src/algorithm/factorization/faust_palm4msa2020_2.hpp
+++ b/src/algorithm/factorization/faust_palm4msa2020_2.hpp
@@ -374,7 +374,7 @@ void Faust::update_lambda(Faust::TransformHelper<FPP,DEVICE>& S, std::vector<Tra
 	gemm(A_H, S_mat, A_H_S, (FPP) 1.0, (FPP) 0.0, 'N', 'N');
 	tr = A_H_S.trace();
 	nS = S_mat.norm();
-	if(std::numeric_limits<Real<FPP>>::epsilon() >= nS)
+	if(Real<FPP>(0) == nS)
 		if(no_lambda_error)
 		{
 			// don't change lambda
@@ -383,6 +383,15 @@ void Faust::update_lambda(Faust::TransformHelper<FPP,DEVICE>& S, std::vector<Tra
 		}
 		else
 			throw std::runtime_error("Error in update_lambda: S Frobenius norm is zero, can't compute lambda.");
+	if(std::isnan(std::real(tr)) || std::isnan(nS))
+		if(no_lambda_error)
+		{
+			// don't change lambda
+			std::cout << "WARNING: lambda didn't change because S contains NaN." << std::endl;
+			return;
+		}
+		else
+			throw std::runtime_error("Error in update_lambda: S (the Faust) contains nan elements in at least one of its matrices, can't compute lambda.");
 	lambda = std::real(tr)/(nS*nS);
 }