svn commit: r291231 - head/usr.bin/ministat
Marcelo Araujo
araujo at FreeBSD.org
Tue Nov 24 02:31:00 UTC 2015
Author: araujo
Date: Tue Nov 24 02:30:59 2015
New Revision: 291231
URL: https://svnweb.freebsd.org/changeset/base/291231
Log:
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 at blazingdot.com>
Reviewed by: imp
Approved by: bapt (mentor)
Modified:
head/usr.bin/ministat/ministat.c
Modified: head/usr.bin/ministat/ministat.c
==============================================================================
--- head/usr.bin/ministat/ministat.c Tue Nov 24 02:27:59 2015 (r291230)
+++ head/usr.bin/ministat/ministat.c Tue Nov 24 02:30:59 2015 (r291231)
@@ -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
More information about the svn-src-head
mailing list