]> https://gitweb.dealii.org/ - dealii.git/commitdiff
tensor.h: Bugfix: make determinant compatible with arbitrary number types
authorMatthias Maier <tamiko@43-1.org>
Tue, 15 Sep 2015 03:26:24 +0000 (22:26 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 15 Sep 2015 18:28:13 +0000 (13:28 -0500)
include/deal.II/base/tensor.h

index ee4159d7af76057cd3cb7bff6b45f8e43520c8cd..54d12dc537c0fabf896a019216a604c86289dd87 100644 (file)
@@ -2129,7 +2129,7 @@ Number determinant (const Tensor<2,dim,Number> &t)
 {
   // Compute the determinant using the Laplace expansion of the
   // determinant. We expand along the last row.
-  Number det = 0;
+  Number det = Number();
 
   for (unsigned int k=0; k<dim; ++k)
     {
@@ -2138,13 +2138,12 @@ Number determinant (const Tensor<2,dim,Number> &t)
         for (unsigned int j=0; j<dim-1; ++j)
           minor[i][j] = t[i][j<k ? j : j+1];
 
-      const Number cofactor = std::pow (-1., static_cast<Number>(k+1)) *
-                              determinant (minor);
+      const Number cofactor = ((k % 2 == 0) ? -1. : 1.) * determinant(minor);
 
       det += t[dim-1][k] * cofactor;
     }
 
-  return std::pow (-1., static_cast<Number>(dim)) * det;
+  return ((dim % 2 == 0) ? 1. : -1.) * det;
 }
 
 #ifndef DOXYGEN

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.