hmmer-3.3/easel/esl_vectorops.c
/* Function:  esl_vec_{DFIL}Sum()
 * Synopsis:  Returns $\sum_i x_i$. 
 *            
 * Purpose:   Returns the scalar sum of the <n> items in <vec>.
 *            
 *            Floating point summations use Kahan compensated
 *            summation, in order to minimize roundoff error
 *            accumulation.  Additionally, they are most
 *            accurate if vec[] is sorted in increasing order, from
 *            small to large, so you may consider sorting <vec> before
 *            summing it.
 */


Returns the scalar sum of the  items in .

Floating point summations use Kahan compensated
summation, in order to minimize roundoff error
accumulation.  Additionally, they are most
accurate if vec[] is sorted in increasing order, from
small to large, so you may consider sorting  before
summing it.
Returns the scalar sum of the items in . Floating point summations use Kahan compensated summation in order to minimize roundoff error accumulation . Additionally they are most accurate if vec [] is sorted in increasing order from small to large so you may consider sorting before summing it .
double 
esl_vec_DSum(const double *vec, int n)
{
  double sum = 0.;
  double y,t,c; 
  int    i;
  c = 0.0;
  for (i = 0; i < n; i++) {
    y = vec[i] - c; t = sum + y; c = (t-sum)-y; sum = t; 
  }
  return sum;
}
double esl_vec_DSum ( const double * vec , int n ) { double sum = 0. ; double y , t , c ; int i ; c = 0.0 ; for ( i = 0 ; i < n ; i ++ ) { y = vec [ i ] - c ; t = sum + y ; c = ( t - sum ) - y ; sum = t ; } return sum ; }
Function:  esl_vec_{DFIL}Sum()
 Synopsis:  Returns $\sum_i x_i$.
Function : esl_vec_ { DFIL } Sum () Synopsis : Returns $ \ sum_i x_i$ .