Look to the rounding of parts of your expression.
The division of 5/9 is
$a / $b = 5 / 9 = 0.555555556
so see http://php.net/manual/en/function.floor.php
floor(1.5) = 1
floor(-1.5) = -2
then
floor(floor($a / $b) - .5) = floor(floor(0.555555556)) = floor(0 - .5) = floor(-.5) = -1
and the second case see http://www.php.net/intval
(int) 4.32 = 4
then
(int)((int)($a / $b) - .5) = (int)((int)(0.555555556) - .5) = (int)(0 - .5) = int(-0.5) = 0;