]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add option to set small numbers to zero.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sun, 5 Nov 2017 17:31:12 +0000 (18:31 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sun, 5 Nov 2017 17:31:12 +0000 (18:31 +0100)
tests/tests.h

index 82fefde5c692925775bcc13b0e2b6f2509ca960e..42eb4a332bf56da80cd5d889b303db5bae2e6bbe 100644 (file)
@@ -259,6 +259,20 @@ std::string unify_pretty_function (const std::string &text)
       }                                                                          \
   }
 
+/*
+ * Allow a test program to define a number that is very small to a given
+ * tolerance to be output as zero. This is used e.g. for the output of float
+ * numbers where roundoff difference can make the error larger than what we
+ * have set for numdiff (that is appropriate for double variables).
+ */
+template <typename Number>
+Number filter_out_small_numbers (const Number number, const double tolerance)
+{
+  if (std::abs(number) < tolerance)
+    return Number();
+  else
+    return number;
+}
 
 // ------------------------------ Functions used in initializing subsystems -------------------
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.