]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix an assertion. 14769/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 8 Feb 2023 20:42:37 +0000 (13:42 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 8 Feb 2023 20:48:51 +0000 (13:48 -0700)
include/deal.II/base/utilities.h

index ef8f22e2cbf3043ac7a85c863293206e10afb3f1..87811ad57bdf20e4fa619011a004ddf351e91831 100644 (file)
@@ -968,17 +968,20 @@ namespace Utilities
   inline T
   fixed_power(const T x)
   {
-    Assert(
-      !std::is_integral<T>::value || (N >= 0),
-      ExcMessage(
-        "The non-type template parameter N must be a non-negative integer for integral type T"));
+    Assert(((std::is_integral<T>::value == true) && (N >= 0)) ||
+             (std::is_integral<T>::value == false),
+           ExcMessage("If the type of the argument, T, is an integer type, "
+                      "then the exponent N must be a non-negative integer "
+                      "because the result would otherwise not be an integer."));
 
     if (N == 0)
       return T(1.);
     else if (N < 0)
+      // For negative exponents, turn things into a positive exponent
       return T(1.) / fixed_power<-N>(x);
     else
-      // Use exponentiation by squaring:
+      // If we get here, we have a positive exponent. Compute the result
+      // by repeated squaring:
       return ((N % 2 == 1) ? x * fixed_power<N / 2>(x * x) :
                              fixed_power<N / 2>(x * x));
   }

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.