Compute the median of the data set as the midpoint between the two middle

values when the data set has an even number of elements.

PR:		201582
Submitted by:	Marcus Reid <marcus@blazingdot.com>
Reviewed by:	imp
Approved by:	bapt (mentor)
This commit is contained in:
Marcelo Araujo 2015-11-24 02:30:59 +00:00
parent 98db8f80a7
commit 19d3ba993d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=291231

View file

@ -192,8 +192,10 @@ Avg(struct dataset *ds)
static double
Median(struct dataset *ds)
{
return (ds->points[ds->n / 2]);
if ((ds->n % 2) == 0)
return ((ds->points[ds->n / 2] + (ds->points[(ds->n / 2) - 1])) / 2);
else
return (ds->points[ds->n / 2]);
}
static double