]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
An experimental convenience function: is_zero
authoryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 11 Feb 2014 10:57:37 +0000 (10:57 +0000)
committeryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 11 Feb 2014 10:57:37 +0000 (10:57 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@32456 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/numbers.h

index ae0f861106ddd57c12021f4974c1c52eaaf93c94..135b90598799d2c4021572fe05c9678827e3748e 100644 (file)
@@ -210,6 +210,12 @@ namespace numbers
      */
     static
     real_type abs (const number &x);
+
+    /**
+     * Return true if this number is zero.
+     */
+    static
+    bool is_zero (const number &x);
   };
 
 
@@ -273,6 +279,12 @@ namespace numbers
      */
     static
     real_type abs (const std::complex<number> &x);
+
+    /**
+     * Return true if this number is zero.
+     */
+    static
+    bool is_zero (const std::complex<number> &x);
   };
 
 }
@@ -319,6 +331,16 @@ namespace numbers
   }
 
 
+  template <typename number>
+  bool
+  NumberTraits<number>::is_zero (const number &x)
+  {
+    if (x == 0)
+      return true;
+    else
+      return false;
+  }
+
 
   template <typename number>
   std::complex<number>
@@ -345,6 +367,17 @@ namespace numbers
     return std::norm (x);
   }
 
+
+  template <typename number>
+  bool
+  NumberTraits<std::complex<number> >::is_zero (const std::complex<number> &x)
+  {
+    if ((std::real (x) == 0) && (std::imag (x) == 0))
+      return true;
+    else
+      return false;
+  }
+
 }
 
 

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.