13 #ifndef OGLPLUS_MATH_COMPILE_TIME_1107121519_HPP
14 #define OGLPLUS_MATH_COMPILE_TIME_1107121519_HPP
16 #include <type_traits>
24 static const unsigned value = Factorial<N-1>::value*N;
30 static const unsigned value = 1;
33 template <
unsigned N,
unsigned K>
36 static_assert(N > 0,
"N must be non-zero");
37 static_assert(K <= N,
"K must be between 0 and N-1");
38 static const unsigned value =
39 (Factorial<N>::value) /
40 (Factorial<N-K>::value * Factorial<K>::value);
44 static T Pow(
T, std::integral_constant<unsigned, 0u>)
49 template <
typename T,
unsigned N>
50 static T Pow(
T v, std::integral_constant<unsigned, N>)
52 return v * Pow<T>(v, std::integral_constant<unsigned, N-1>());
59 template <
typename T,
typename P,
unsigned N>
63 template <
unsigned M,
unsigned I>
65 std::integral_constant<unsigned, M>,
66 std::integral_constant<unsigned, I>,
70 return Binomial<M, I>::value *
71 Pow<P>(t, std::integral_constant<unsigned, I>()) *
72 Pow<P>(P(1)-t, std::integral_constant<unsigned, M-I>());
78 std::integral_constant<unsigned, 0> ,
79 std::integral_constant<unsigned, I> i,
84 std::integral_constant<unsigned, N> n;
85 return _bi(n, i, t) * v[I];
92 std::integral_constant<unsigned, 1> ,
93 std::integral_constant<unsigned, I> i,
98 std::integral_constant<unsigned, N-1> n_1;
99 return _bi(n_1, i, t) * N * (v[I+1] - v[I]);
104 template <
unsigned I>
106 std::integral_constant<unsigned, 2> ,
107 std::integral_constant<unsigned, I> i,
112 std::integral_constant<unsigned, N-2> n_2;
113 return _bi(n_2, i, t) * N*(N - 1) * (v[I+2] - 2*v[I+1] + v[I]);
116 template <
unsigned D>
118 std::integral_constant<unsigned, D> d,
119 std::integral_constant<unsigned, 0> i,
124 return _f(d, i, v, t);
127 template <
unsigned D,
unsigned I>
129 std::integral_constant<unsigned, D> d,
130 std::integral_constant<unsigned, I> i,
135 std::integral_constant<unsigned, I-1> i_1;
136 return _sum(d, i_1, v, t) + _f(d, i, v, t);
140 template <
unsigned D>
142 std::integral_constant<unsigned, D> d,
150 std::integral_constant<unsigned, N-D> n_d;
151 return _sum(d, n_d, v, t);
154 static T Position(
const T* v,
size_t s, P t)
156 std::integral_constant<unsigned, 0> d;
157 return B(d, v, s, t);
160 static T Derivative1(
const T* v,
size_t s, P t)
162 std::integral_constant<unsigned, 1> d;
163 return B(d, v, s, t);
166 static T Derivative2(
const T* v,
size_t s, P t)
168 std::integral_constant<unsigned, 2> d;
169 return B(d, v, s, t);
177 template <
typename T,
typename W,
typename P,
unsigned N>
181 template <
unsigned I>
183 std::integral_constant<unsigned, I>,
189 return Binomial<N, I>::value *
190 Pow<P>(t, std::integral_constant<unsigned, I>()) *
191 Pow<P>(P(1)-t, std::integral_constant<unsigned, N-I>())*
196 std::integral_constant<unsigned, 0> i,
202 return _part(i, v, w, t);
205 template <
unsigned I>
207 std::integral_constant<unsigned, I> i,
213 std::integral_constant<unsigned, I-1> i_1;
214 return _sum(i_1, v, w, t) + _part(i, v, w, t);
216 template <
unsigned I>
217 static W _part(std::integral_constant<unsigned, I>,
const W* w, P t)
219 return Binomial<N, I>::value *
220 Pow<P>(t, std::integral_constant<unsigned, I>()) *
221 Pow<P>(P(1)-t, std::integral_constant<unsigned, N-I>())*
225 static W _sum(std::integral_constant<unsigned, 0> i,
const W* w, P t)
227 return _part(i, w, t);
230 template <
unsigned I>
231 static W _sum(std::integral_constant<unsigned, I> i,
const W* w, P t)
233 std::integral_constant<unsigned, I-1> i_1;
234 return _sum(i_1, w, t) + _part(i, w, t);
237 static T Calc(
const T* v,
const W* w,
size_t s, P t)
240 std::integral_constant<unsigned, N> n;
241 return _sum(n, v, w, t)*(W(1)/_sum(n, w, t));
248 #endif // include guard