|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50622 minus 0 returned
Submitted: 2009-12-31 14:30 UTC Modified: 2009-12-31 14:38 UTC
From: okycastro at gmail dot com Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.2.12 OS: windows vista
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: okycastro at gmail dot com
New email:
PHP Version: OS:


 [2009-12-31 14:30 UTC] okycastro at gmail dot com
-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

if ($x <= 0) //$x = -0

Reproduce code:
$i= (float) -90;
$a= (int) 0;
echo floor($i * ($a / 100));


$i= (int) -90;
$a= (int) 0;
echo floor($i * ($a / 100));
returns 0;//OK

Expected result:
0 should be returned always

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-31 14:38 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 12:01:29 2024 UTC