]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Pass scalars by value and fix a relative tolerance 14309/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 26 Sep 2022 09:37:33 +0000 (11:37 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 26 Sep 2022 09:38:02 +0000 (11:38 +0200)
include/deal.II/base/floating_point_comparator.h

index eef3f96b469a55647b0ee2d9f11779daa2b5dba3..b4bb6967eaacded3746f48b426b38b3c503656fd 100644 (file)
@@ -116,7 +116,7 @@ struct FloatingPointComparator
    * Compare two scalar numbers.
    */
   ComparisonResult
-  compare(const ScalarNumber &s1, const ScalarNumber &s2) const;
+  compare(const ScalarNumber s1, const ScalarNumber s2) const;
 
   /**
    * Compare two VectorizedArray instances.
@@ -240,14 +240,15 @@ FloatingPointComparator<Number>::compare(const Table<2, T> &t1,
 
 template <typename Number>
 typename FloatingPointComparator<Number>::ComparisonResult
-FloatingPointComparator<Number>::compare(const ScalarNumber &s1,
-                                         const ScalarNumber &s2) const
+FloatingPointComparator<Number>::compare(const ScalarNumber s1,
+                                         const ScalarNumber s2) const
 {
   if (width == 1 || mask[0])
     {
-      const ScalarNumber tolerance = use_absolute_tolerance ?
-                                       this->tolerance :
-                                       (std::abs(s1 + s2) * this->tolerance);
+      const ScalarNumber tolerance =
+        use_absolute_tolerance ?
+          this->tolerance :
+          ((std::abs(s1) + std::abs(s2)) * this->tolerance);
 
       if (s1 < s2 - tolerance)
         return ComparisonResult::less;

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.