php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46781 BC math handles minus zero incorrectly
Submitted: 2008-12-06 12:39 UTC Modified: 2017-09-11 15:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: preechaw at gmail dot com Assigned: cmb (profile)
Status: Closed Package: BC math related
PHP Version: 5.2.7 OS: Windows XP
Private report: No CVE-ID: None
 [2008-12-06 12:39 UTC] preechaw at gmail dot com
Description:
------------
bcadd("-0.0", "-0.0", 1); // returns -0.0
bccomp("-0.0", "0", 1); // returns -1

I believe that the first expression should return '0.0', 
and the second one should return 0.

The second expression implies that "-0.0" is mathematically less than "0", which is incorrect.

--
I also submitted another bug related to minus zero.
echo -0.1 * 0; // returns -0
--


Reproduce code:
---------------
<?php
echo bcadd("-0.0", "-0.0", 1) . "<br>\n"; // returns -0.0
echo bccomp("-0.0", "0", 1) . "<br>\n"; // returns -1
?>


Expected result:
----------------
-0.0
-1


Actual result:
--------------
0.0
0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-21 20:01 UTC] jani@php.net
I get the expected result with current release. (5.2.8)
 [2011-04-16 21:00 UTC] testify4 at o2 dot pl
jani@php.net, "expected result" that you got is obviously incorrect. I am using PHP 5.3.3 and this bug still exists. Please change the bug status. Thank you.

Reproduce code:
---------------

<?php
bcscale(2);
print bcadd('-0.0', '-0.0') . '<br>'; // prints: -0.00, should be: 0.00
print bccomp('-0.0', '0') . '<br>'; // prints: -1, should be: 0
?>
 [2017-09-11 15:16 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Assigned To: +Assigned To: cmb
 [2017-09-11 15:16 UTC] cmb@php.net
Indeed, that's still broken, see <https://3v4l.org/J93YJ>.
 [2017-09-11 22:03 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9aa6898b9be78bb1e138488c3204bb745a31aca7
Log: Fixed bug #46781 (BC math handles minus zero incorrectly)
 [2017-09-11 22:03 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC