]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use the boost implementation of binomials.
authorDavid Wells <wellsd2@rpi.edu>
Sat, 29 Aug 2015 17:32:16 +0000 (13:32 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 29 Aug 2015 21:43:03 +0000 (17:43 -0400)
source/base/polynomials_bernstein.cc

index f32cdb3da624c33e493f67d52b84f4c4b9ebf7e0..c9c3e8849bdbef4da2e04c5ccd2e8c492b4cc59e 100644 (file)
@@ -1,34 +1,13 @@
-
 #include <deal.II/base/polynomials_bernstein.h>
+
+#include <boost/math/special_functions/binomial.hpp>
+
 #include <vector>
 
 DEAL_II_NAMESPACE_OPEN
 
 namespace Binomial
 {
-  unsigned int
-  factorial (
-    unsigned int k)
-  {
-    if (k > 1)
-      return k * factorial(k - 1);
-    else
-      return 1;
-  }
-
-  inline unsigned int
-  binomial (
-    const unsigned int nValue, const unsigned int nValue2)
-  {
-    Assert(nValue >= nValue2,
-           ExcMessage("nValue should be greater or equal than nValue2"));
-    if (nValue2 == 1)
-      return nValue;
-    else
-      return ((factorial(nValue))
-              / (factorial(nValue2) * factorial((nValue - nValue2))));
-  }
-
   template <typename number>
   std::vector<number>
   get_bernstein_coefficients (
@@ -38,11 +17,13 @@ namespace Binomial
     AssertIndexRange(k, n+1);
     std::vector<number> coeff(n + 1, number(0.0));
     for (unsigned int i = k; i < n + 1; ++i)
-      coeff[i] = (pow(number(-1), number(i - k)) * binomial(n, i)
-                  * binomial(i, k));
+      {
+        coeff[i] = pow(number(-1), number(i - k))
+                   * boost::math::binomial_coefficient<number>(n, i)
+                   * boost::math::binomial_coefficient<number>(i, k);
+      }
     return coeff;
   }
-
 }
 
 template <typename number>

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.