Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Nov 2015 02:30:59 +0000 (UTC)
From:      Marcelo Araujo <araujo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r291231 - head/usr.bin/ministat
Message-ID:  <201511240230.tAO2UxvB015207@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511240230.tAO2UxvB015207>