#48968 [Opn->Bgs]: (float) "NAN" gives float(0.0) rather than float(NAN)
ID: 48968
Updated by: jani@php.net
Reported By: salsi at icosaedro dot it
-Status: Open
+Status: Bogus
Bug Type: *General Issues
PHP Version: 5.3.0
New Comment:
Those are strings. There's no such magic available that can guess
you're not passing string but a number there..
Previous Comments:
------------------------------------------------------------------------
[2009-07-18 08:28:42] salsi at icosaedro dot it
Description:
------------
The (float) typecast operator applied to a string is expected to return
the floating point number represented by the string, instead the special
values "NAN", "INF" and "-INF" are not handled properly and give 0.0,
0.0 and -0.0 respectively.
To make the (float) operator applied to a string symmetrical versus the
(string) operator applied to a float, the special strings "NAN", "INF"
and "-INF" case sensitive should be translated into NAN, INF and -INF
respectively:
$f = NAN;
$s = (string) $f; # ==> "NAN"
$g = (float) $s; # ==> NAN again
Apparently the serialize/unserialize process works properly as it was
fixed in bug #27646:
var_dump( unserialize(serialize(NAN)) ) ==> float(NAN)
Reproduce code:
---------------
var_dump( (float) "INF" ); # expected float(INF)
var_dump( (float) "-INF" ); # expected float(-INF)
var_dump( (float) "NAN" ); # expected float(NAN)
Expected result:
----------------
float(INF)
float(-INF)
float(NAN)
Actual result:
--------------
float(0)
float(-0)
float(0)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48968&edit=1
Thread (2 messages)