Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strange result of multiplying by -1

$res = 0.0 * -1.0;

I get float -0

What is this strange behavior?

like image 397
ilya iz Avatar asked Mar 03 '12 12:03

ilya iz


2 Answers

Floating point numbers allow have a signed zero.

You shouldn't worry, however, as +0.0 === -0.0 (demo). (Not that you should use that sort of comparison for floats.)

like image 64
Sebastian Paaske Tørholm Avatar answered Nov 06 '22 14:11

Sebastian Paaske Tørholm


Because floating-point has both +0 and -0.

like image 45
Oliver Charlesworth Avatar answered Nov 06 '22 16:11

Oliver Charlesworth