From: young Date: Tue, 11 Feb 2014 10:57:37 +0000 (+0000) Subject: An experimental convenience function: is_zero X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e78268846510d558e770b3203b06a6e315adf3d7;p=dealii-svn.git An experimental convenience function: is_zero git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@32456 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/numbers.h b/deal.II/include/deal.II/base/numbers.h index ae0f861106..135b905987 100644 --- a/deal.II/include/deal.II/base/numbers.h +++ b/deal.II/include/deal.II/base/numbers.h @@ -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 &x); + + /** + * Return true if this number is zero. + */ + static + bool is_zero (const std::complex &x); }; } @@ -319,6 +331,16 @@ namespace numbers } + template + bool + NumberTraits::is_zero (const number &x) + { + if (x == 0) + return true; + else + return false; + } + template std::complex @@ -345,6 +367,17 @@ namespace numbers return std::norm (x); } + + template + bool + NumberTraits >::is_zero (const std::complex &x) + { + if ((std::real (x) == 0) && (std::imag (x) == 0)) + return true; + else + return false; + } + }