compile time template bernstein polynomial I wrote a compile time bernstein polynomial instead to define several functions for different coefficients. I wonder whether there is a way to make the function faster. std::powf is known to be relatively slow and the binominal coefficient is for some cases 1. Also style fixes are appreciated. 

// Template functions to estimate the binominal coefficient
template&lt;uint8_t n, uint8_t k&gt;
struct binomial {
  static constexpr int value = (binomial&lt;n - 1, k - 1&gt;::value + binomial&lt;n - 1, k&gt;::value);
};

template&lt;&gt;
struct binomial&lt;0, 0&gt; {
  static constexpr int value = 1;
};

template&lt;uint8_t n&gt;
struct binomial&lt;n, 0&gt; {
  static constexpr int value = 1;
};

template&lt;uint8_t n&gt;
struct binomial&lt;n, n&gt; {
  static constexpr int value = 1;
};

// Template bernstein polynomial
template &lt;uint8_t n, uint8_t k&gt;
float bernstein(const float val) {
  constexpr float binom_coeff = binomial&lt;n, k&gt;::value;
  const float a = std::powf(val, k);
  const float b = std::powf(1 - val, n - k);
  return binom_coeff * a * b;
}
You could check against the most common cases you expect to occur:

float a;
switch (k)
{
case 0:
    a = 1.0f;
    break;
case 1:
    a = val;
    break;
case 2:
    a = val*val;
    break;
// maybe some more common cases...
default:
    a = std::powf(val, k);
}


But I personally wouldn't do such optimizations unless you really see that there is some significant slowdown in your particular case and benchmarks show that such an optimization really does make a difference.