php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
48 - 42 = ?
Subscribe to this entry?

 
 [2009-12-31 14:30 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-31 14:38 UTC] rasmus@php.net
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: Sat Jun 22 12:01:30 2024 UTC