#48968 [NEW]: (float) "NAN" gives float(0.0) rather than float(NAN)
From: salsi at icosaedro dot it
Operating system:
PHP version: 5.3.0
PHP Bug Type: *General Issues
Bug description: (float) "NAN" gives float(0.0) rather than float(NAN)
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 bug report at http://bugs.php.net/?id=48968&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48968&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48968&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48968&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=48968&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=48968&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48968&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48968&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48968&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48968&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48968&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48968&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48968&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48968&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48968&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48968&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48968&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48968&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48968&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48968&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48968&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48968&r=mysqlcfg
Thread (2 messages)
- salsi at icosaedro dot it