diff --git a/python/dune/perftool/pdelab/driver.py b/python/dune/perftool/pdelab/driver.py
index d0b403633da5c79610b261be51a8242446f44a73..303425bcd794f5d2c12d3d07c9dd4b784af6b31f 100644
--- a/python/dune/perftool/pdelab/driver.py
+++ b/python/dune/perftool/pdelab/driver.py
@@ -1293,7 +1293,7 @@ def compare_L2_squared():
     accum_error = name_accumulated_L2_error()
     fail = name_test_fail_variable()
     return ["std::cout << \"l2errorsquared: \" << {} << std::endl;".format(accum_error),
-            "if ({}>{})".format(accum_error, get_option("compare_l2errorsquared")),
+            "if (std::isnan({0}) or std::abs({0})>{1})".format(accum_error, get_option("compare_l2errorsquared")),
             "  {} = true;".format(fail)]