Edit report at https://bugs.php.net/bug.php?id=52355&edit=1
ID: 52355
Comment by: salsi at icosaedro dot it
Reported by: spoon dot reloaded at gmail dot com
Summary: Negating zero does not produce negative zero
Status: Open
Type: Feature/Change Request
Package: Math related
PHP Version: 5.3.2
Block user comment: N
Private report: N
New Comment:
The zero negative could appear also in the simplest expressions, yielding quite
unexpected results, as in
$zn = -1 * 0.0;
echo $zn; ==> -0
Under PHP several int expressions might result in a float value, and most
programmers are unaware that their "exact" calculations are made in the quite
obscure domain of the approximated floating-point numbers, possibly with safety
and security related issues.
Since $zn==0.0 and $zn===0.0 are both true, the only way I have found to detect
the zero negative value is by comparing its representation as a string:
if( $f === 0.0 and "$f" === "-0" )
echo "WARNING: it's zero negative!";
Previous Comments:
------------------------------------------------------------------------
[2010-07-16 08:34:29] spoon dot reloaded at gmail dot com
Nor can you specify -0 as a float literal:
var_dump(-0.);
float(0)
------------------------------------------------------------------------
[2010-07-16 08:31:54] spoon dot reloaded at gmail dot com
Description:
------------
Using the unary negation operator on a float 0 (positive zero) value, simply
returns positive zero again, instead of -0 (negative zero), like it does in
other languages.
var_dump(-(0.));
float(0)
The negative zero exists and can be displayed properly, so that is not the
problem:
var_dump(-1/INF);
float(-0)
But for some reason there is no easy way to access it.
Test script:
---------------
var_dump(-(0.));
var_dump(-1/INF);
Expected result:
----------------
float(-0)
float(-0)
Actual result:
--------------
float(0)
float(-0)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52355&edit=1