Special Excel-meaning of median.



Hi,

I might be losing it, but staring at this code I don't see the `special excel meaning'.
"

/* Special Excel-meaning of median.  */
static int
range_excel_median (const gnum_float *xs, int n, gnum_float *res)
{
  if (n > 0) {
      /* OK, so we ignore the constness here.  Tough.  */
      qsort ((gnum_float *) xs, n, sizeof (xs[0]),
             (void *) &float_compare);
      if (n & 1)
          *res = xs[n / 2];
      else
          *res = (xs[n / 2 - 1] + xs[n / 2]) / 2;
      return 0;
  } else
      return 1;
}

It looks to me like the usual median:
The median of n sorted values x[1] <= x[2] <= ...<= x[n] is x[(n+1)/2] if n is odd and
1/2 (x[n/2]+x[n/2+1]) if n is even.

In any case, it would be nice to use this function in analysis-tools.c. That's why I am wondering whether this function shouldn't be in math-func.h/c with all the other range_* functions rather than in fn-stats.c?

Andreas

--
Prof. Dr. Andreas J. Guelzow Assoc. Prof of Mathematics
Concordia University College of Alberta
http://www.math.concordia.ab.ca/aguelzow





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]