aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Araujo <araujo@FreeBSD.org>2015-11-24 02:30:59 +0000
committerMarcelo Araujo <araujo@FreeBSD.org>2015-11-24 02:30:59 +0000
commit19d3ba993dc5ffa351fbe3b06e04d887991700ef (patch)
tree12c42bdb09e68b60dcd96bae064b4cbfa44fb8fd
parent98db8f80a71e985b3949b6fbb524aeae28215226 (diff)
downloadsrc-19d3ba993dc5ffa351fbe3b06e04d887991700ef.tar.gz
src-19d3ba993dc5ffa351fbe3b06e04d887991700ef.zip
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)
Notes
Notes: svn path=/head/; revision=291231
-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 59beac7127f9..a7f7182ce420 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