PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Math » Math_Stats » Bug #2322

There's an error in function median() in current _stable_ release

Details

Submitted2004-09-13 17:35 UTC
Fromtomasz dot frelik at enzo dot pl
StatusBogus
PackageMath_Stats
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-09-13 17:35 UTC] tomasz dot frelik at enzo dot pl

Description:
------------
Original code in median():

$n = count($arr);
$h = intval($n / 2);
if ($n % 2 == 0) {
$median = ($arr[$h] + $arr[$h - 1]) / 2;
} else {
$median = $arr[$h + 1]; // <--- HERE
}

I believe the line should read

$median = $arr[$h];

For example, n=5, h=intval(2.5), h=2
We are interested in the 3rd element of an array, it's index is 2.

[2004-09-14 11:56 UTC] tomasz dot frelik at enzo dot pl

There are two versions of the package in Current Release section. I downloaded the one labeled "stable", because I'd assume that's the right choice when looking for production-quality code. The bug is fixed in "beta", but still present in "stable" release.