summaryrefslogtreecommitdiffstats
path: root/usr.bin/ministat
diff options
context:
space:
mode:
authoraraujo <araujo@FreeBSD.org>2015-11-24 02:30:59 +0000
committeraraujo <araujo@FreeBSD.org>2015-11-24 02:30:59 +0000
commit835b818769c9408e6929b658b306e9ba1802e2ed (patch)
tree12c42bdb09e68b60dcd96bae064b4cbfa44fb8fd /usr.bin/ministat
parentba54012c272f6b0d9d93a4e340d8ea6d36609f60 (diff)
downloadFreeBSD-src-835b818769c9408e6929b658b306e9ba1802e2ed.zip
FreeBSD-src-835b818769c9408e6929b658b306e9ba1802e2ed.tar.gz
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)
Diffstat (limited to 'usr.bin/ministat')
-rw-r--r--usr.bin/ministat/ministat.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.bin/ministat/ministat.c b/usr.bin/ministat/ministat.c
index 59beac7..a7f7182 100644
--- a/usr.bin/ministat/ministat.c
+++ b/usr.bin/ministat/ministat.c
@@ -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
OpenPOWER on IntegriCloud