From e78268846510d558e770b3203b06a6e315adf3d7 Mon Sep 17 00:00:00 2001 From: young Date: Tue, 11 Feb 2014 10:57:37 +0000 Subject: [PATCH] An experimental convenience function: is_zero 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 | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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; + } + } -- 2.39.5