php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48968 (float) "NAN" gives float(0.0) rather than float(NAN)
Submitted: 2009-07-18 08:28 UTC Modified: 2009-07-20 09:40 UTC
From: salsi at icosaedro dot it Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.0 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: salsi at icosaedro dot it
New email:
PHP Version: OS:

 

 [2009-07-18 08:28 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-20 09:40 UTC] jani@php.net
Those are strings. There's no such magic available that can guess you're not passing string but a number there..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC