From 79f489f68f7ab8aea2259a4c26350a3b918d3a9a Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Thu, 22 Oct 2015 08:34:40 +0200
Subject: [PATCH] Avoid division by zero

I used nummeric_limits::max() instead of numeric_limits::infinity() here
because the header uses the former to signify an error that cannot lie
below any tolerance elsewhere already.
---
 dune/solvers/solvers/loopsolver.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/dune/solvers/solvers/loopsolver.cc b/dune/solvers/solvers/loopsolver.cc
index 799f05df..d33da8ff 100644
--- a/dune/solvers/solvers/loopsolver.cc
+++ b/dune/solvers/solvers/loopsolver.cc
@@ -112,8 +112,9 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
         }
 
         // Turn the error into the relative error, if requested
-        if (this->useRelativeError_ && !std::isnan(error/oldNorm))
-            error = error / oldNorm;
+        if (this->useRelativeError_ && error != 0)
+            error = (oldNorm == 0) ? std::numeric_limits<real_type>::max()
+                                   : error / oldNorm;
 
         if (!std::isinf(convRate) && !std::isnan(convRate) && i>0)
         {
-- 
GitLab