]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Compute powers of -1 by checking exponent parity.
authorDavid Wells <wellsd2@rpi.edu>
Sat, 29 Aug 2015 17:33:54 +0000 (13:33 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 29 Aug 2015 21:44:25 +0000 (17:44 -0400)
source/base/polynomials_bernstein.cc

index c9c3e8849bdbef4da2e04c5ccd2e8c492b4cc59e..942d3e93140cb59b18cbce9c2eefd0410d54a69c 100644 (file)
@@ -18,7 +18,7 @@ namespace Binomial
     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))
+        coeff[i] = ((i - k) % 2 == 0 ? 1 : -1)
                    * boost::math::binomial_coefficient<number>(n, i)
                    * boost::math::binomial_coefficient<number>(i, k);
       }

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.