Home » Math » Math_Stats » Bug #2322
There's an error in function median() in current _stable_ release
Details
| Submitted | 2004-09-13 17:35 UTC |
|---|---|
| From | tomasz dot frelik at enzo dot pl |
| Status | Bogus |
| Package | Math_Stats |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| 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.