ilya iz
ilya iz

Reputation: 470

PHP strange result of multiplying by -1

$res = 0.0 * -1.0;

I get float -0

What is this strange behavior?

Upvotes: 6

Views: 145

Answers (2)

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.)

Upvotes: 8

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272467

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

Upvotes: 6

Related Questions