php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53865 (float)0 * -1 = minus zero (-0)
Submitted: 2011-01-28 10:03 UTC Modified: 2011-01-28 11:23 UTC
From: dmitrij at stepanov dot lv Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.5 OS: Windows 7
Private report: No CVE-ID:
 [2011-01-28 10:03 UTC] dmitrij at stepanov dot lv
Description:
------------
See test script.

Test script:
---------------
var_dump( (float)0 * -1);

Expected result:
----------------
float(0)

Actual result:
--------------
float(-0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-28 11:23 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-01-28 11:23 UTC] derick@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.

.
 [2011-01-28 11:33 UTC] dmitrij at stepanov dot lv
I guess the link should be http://en.wikipedia.org/wiki/IEEE_754
 [2011-01-28 14:35 UTC] abc at abc dot abc
Oracle went crapping all over the Sun website a few months ago and broke tons of links. PHP bug reviewers give so little attention to each bug that they're still giving template replies to each bogus float bug with the same broken link.

The correct answer to your problem is that this is a feature of the (IEEE 754) floating-point format. It supports positive and negative zero. The example you gave is behaving exactly as it should.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC