]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Added is_finite() function for complex numbers
authorallmaras <allmaras@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 19 Oct 2007 20:09:51 +0000 (20:09 +0000)
committerallmaras <allmaras@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 19 Oct 2007 20:09:51 +0000 (20:09 +0000)
git-svn-id: https://svn.dealii.org/trunk@15353 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/numbers.h
deal.II/base/source/config.cc
deal.II/lac/include/lac/vector.h

index cdf52f15a99c07b87cc0094a97a7f487065c860b..6439644bf46d20b7ae5fd99cf6e4caf81bdffb3d 100644 (file)
@@ -15,6 +15,7 @@
 
 
 #include <base/config.h>
+#include <complex>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -102,12 +103,12 @@ namespace deal_II_numbers {
                                               */
   static const double  SQRT1_2 = 0.70710678118654752440;
 
-                                            /**
-                                             * Return @p true if the given
-                                             * value is a finite floating
-                                             * point number, i.e. is neither
-                                             * plus or minus infinity nor NaN
-                                             * (not a number).
+                                             /**
+                                             * Return @p true if the given
+                                             * value is a finite floating
+                                             * point number, i.e. is neither
+                                             * plus or minus infinity nor NaN
+                                             * (not a number).
                                              *
                                              * Note that the argument type of
                                              * this function is
@@ -120,8 +121,29 @@ namespace deal_II_numbers {
                                              * number is finite with respect
                                              * to type <code>long
                                              * double</code>.
-                                             */
+                                             */
   bool is_finite (const double x);
+
+                                             /**
+                                             * Return @p true if real and 
+                                             * imaginary parts of the given
+                                             * complex number are finite.
+                                             */
+  bool is_finite (const std::complex<double> x);
+
+                                             /**
+                                             * Return @p true if real and 
+                                             * imaginary parts of the given
+                                             * complex number are finite.
+                                             *
+                                             * Again may not work correctly if
+                                             * real or imaginary parts are very        
+                                             * large numbers that are infinite in 
+                                             * terms of <code>double</code>, but 
+                                             * finite with respect to 
+                                             * <code>long double</code>.
+                                             */
+  bool is_finite (const std::complex<long double> x);
 }
 
 DEAL_II_NAMESPACE_CLOSE
index 80b5f4581afbf6ef155d43fcfe6a46d976fdba9c..46092dc9e1fe5bc9ac7cb9f95d0196d3e8864a10 100644 (file)
@@ -15,6 +15,7 @@
 #include <base/config.h>
 #include <cmath>
 #include <limits>
+#include <complex>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -25,7 +26,7 @@ namespace deal_II_numbers
 #ifdef DEAL_II_HAVE_ISFINITE
     return std::isfinite (x);
 #else
-                                    // check against infinities. not
+                                    // Check against infinities. Note
                                     // that if x is a NaN, then both
                                     // comparisons will be false
     return ((x >= -std::numeric_limits<double>::max())
@@ -33,6 +34,27 @@ namespace deal_II_numbers
            (x <= std::numeric_limits<double>::max()));
 #endif
   }
+
+
+
+  bool is_finite (const std::complex<double> x) 
+  {
+                                       // Check complex numbers for infinity
+                                       // by testing real and imaginary part
+    return ( is_finite (x.real()) 
+             && 
+             is_finite (x.imag()) );
+  }
+
+
+
+  bool is_finite (const std::complex<long double> x) 
+  {
+                                       // Same for std::complex<long double>
+    return ( is_finite (x.real()) 
+             && 
+             is_finite (x.imag()) );
+  }
 }
 
 DEAL_II_NAMESPACE_CLOSE
index 7251f05525a6421dd45f90991a6d894651e3a14e..628c0a32914da3bf59c3166df104e20a0906d011 100644 (file)
@@ -857,7 +857,7 @@ Vector<Number> & Vector<Number>::operator = (const Number s)
   Assert (deal_II_numbers::is_finite(s), 
           ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
   
-  if (s != 0.)
+  if (s != Number())
     Assert (vec_size!=0, ExcEmptyObject());
   if (vec_size!=0)
     std::fill (begin(), end(), s);

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.