From 38acfeacb3244ba0c20d25203ff60f6f25297acd Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Tue, 9 May 2023 11:05:26 -0400
Subject: [PATCH] Add runtime check in rootfinding

---
 include/teqp/algorithms/rootfinding.hpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/teqp/algorithms/rootfinding.hpp b/include/teqp/algorithms/rootfinding.hpp
index 4f2e792..e9e54f0 100644
--- a/include/teqp/algorithms/rootfinding.hpp
+++ b/include/teqp/algorithms/rootfinding.hpp
@@ -18,6 +18,9 @@ auto NewtonRaphson(Callable f, const Inputs& args, double tol) {
         Eigen::ArrayXd v = J.colPivHouseholderQr().solve(-r0.matrix());
         x += v;
         auto err = r0.matrix().norm();
+        if (!std::isfinite(err)){
+            throw std::invalid_argument("err is now NaN");
+        }
         if (err < tol) {
             break;
         }
-- 
GitLab