MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / SetBernoulliNumbersSum

Function SetBernoulliNumbersSum

extern/ttmath/ttmath.h:2233–2272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 /*!

Callers 1

SetBernoulliNumbersMoreFunction · 0.85

Calls 7

ValueTypeEnum · 0.85
SetZeroMethod · 0.80
WasStopSignalMethod · 0.80
PowMethod · 0.45
MulMethod · 0.45
DivMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected