| 2231 | */ |
| 2232 | template<class ValueType> |
| 2233 | ValueType SetBernoulliNumbersSum(CGamma<ValueType> & cgamma, const ValueType & n_, uint m, |
| 2234 | const volatile StopCalculating * stop = 0) |
| 2235 | { |
| 2236 | ValueType k_, temp, temp2, temp3, sum; |
| 2237 | |
| 2238 | sum.SetZero(); |
| 2239 | |
| 2240 | for(uint k=0 ; k<m ; ++k) // k<m means k<=m-1 |
| 2241 | { |
| 2242 | if( stop && (k & 15)==0 ) // means: k % 16 == 0 |
| 2243 | if( stop->WasStopSignal() ) |
| 2244 | return ValueType(); // NaN |
| 2245 | |
| 2246 | if( k>1 && (k & 1) == 1 ) // for that k the Bernoulli number is zero |
| 2247 | continue; |
| 2248 | |
| 2249 | k_ = k; |
| 2250 | |
| 2251 | temp = n_; // n_ is equal 2 |
| 2252 | temp.Pow(k_); |
| 2253 | // temp = 2^k |
| 2254 | |
| 2255 | temp2 = cgamma.fact[m]; |
| 2256 | temp3 = cgamma.fact[k]; |
| 2257 | temp3.Mul(cgamma.fact[m-k]); |
| 2258 | temp2.Div(temp3); |
| 2259 | // temp2 = (m k) = m! / ( k! * (m-k)! ) |
| 2260 | |
| 2261 | temp.Mul(temp2); |
| 2262 | temp.Mul(cgamma.bern[k]); |
| 2263 | |
| 2264 | sum.Add(temp); |
| 2265 | // sum += 2^k * (m k) * B(k) |
| 2266 | |
| 2267 | if( sum.IsNan() ) |
| 2268 | break; |
| 2269 | } |
| 2270 | |
| 2271 | return sum; |
| 2272 | } |
| 2273 | |
| 2274 | |
| 2275 | /*! |
no test coverage detected