Skip to content

Commit 131aca2

Browse files
artumi-richardtegos
authored andcommitted
median() div swapped for intdiv() (laravel#57148)
Finding the middle of a list of values using the float div operator (/) is wrong, and goes wrong at some higher values where the int/2 is not representable as a float to single digit precision. That's why intdiv() exists.
1 parent e0b7d84 commit 131aca2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function median($key = null)
9595
return;
9696
}
9797

98-
$middle = (int) ($count / 2);
98+
$middle = intdiv($count, 2);
9999

100100
if ($count % 2) {
101101
return $values->get($middle);

0 commit comments

Comments
 (0)