I have a function that calculates a value that is a float:
function crunch (float $a, float $b):float
{
//do stuff
return $result;
}
function testSomething (float $a, float $b):bool
{
//if $result is -0 that returns false
$result = crunch($a, $b);
return $result === 0;
}
Why is -0 not equal to 0 and how can one safely check if this number is equal if it 0should be the same as -0?
UPDATE
Since the question arose, for more details. I have a class Vec2that has x()both y()getters and a method called crossthat looks like this:
public function cross(Vec2 $vec2):float
{
return ($this->_x * $vec2->_y) - ($vec2->_x * $this->_y);
}
Running this code:
$cross = $this->cross($d);
causes the debugger output

and $cross === 0is rated as false;
source
share