#50622 [Opn->Bgs]: minus 0 returned
| From: | rasmus@php.net | Date: | Thu, 31 Dec 2009 14:38:52 +0000 |
| Subject: | #50622 [Opn->Bgs]: minus 0 returned | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-146243@lists.php.net to get a copy of this message | ||
ID: 50622
Updated by: rasmus@php.net
Reported By: okycastro at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: *Math Functions
Operating System: windows vista
PHP Version: 5.2.12
New Comment:
Computers use IEEE754's two's complement method to store floating point
numbers. That standard has both +0 and -0, for better or worse. When
computers store integers you only have one 0. So, in your case, since
you are obviously interested in the integer floor, you should change
your code to:
$i= (float) -90;
$a= (int) 0;
echo (int)floor($i * ($a / 100));
We are not going to stray from IEEE754 here. Every language out there
does exactly the same.
Previous Comments:
------------------------------------------------------------------------
[2009-12-31 14:30:04] okycastro at gmail dot com
Description:
------------
-0 is returns under the following example. I believe this is a bug. I
see there was a bug about this a long time ago, But I think that the
concept of a -0 is an invalid one. it just makes no sense. Even more if
you consider that the following line will never gets executed
if ($x < 0) //$x = -0
//NEVER EXECUTED
if ($x <= 0) //$x = -0
//GETS EXECUTED
Reproduce code:
---------------
$i= (float) -90;
$a= (int) 0;
echo floor($i * ($a / 100));
returns -0;//MY OPINION IS AN ERROR
$i= (int) -90;
$a= (int) 0;
echo floor($i * ($a / 100));
returns 0;//OK
Expected result:
----------------
0 should be returned always
Actual result:
--------------
-0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50622&edit=1