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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or 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

Add a Patch

Pull Requests

Add a Pull Request

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 May 12 16:01:35 2024 UTC