php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73329 (Float)"Nano" == NAN [Should return me 0]
Submitted: 2016-10-17 10:59 UTC Modified: 2016-10-17 17:33 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: nikcomestotalk at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.12 OS: Any
Private report: No CVE-ID: None
 [2016-10-17 10:59 UTC] nikcomestotalk at gmail dot com
Description:
------------
(Float)"Nano" == NAN [Should return me 0]

(Float)"Information" == NAN [Should return me 0]

Expected result:
----------------
Should return me 0

Actual result:
--------------
NAN or INF

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-17 11:27 UTC] requinix@php.net
-Status: Open +Status: Verified -Package: Variables related +Package: Scripting Engine problem
 [2016-10-17 12:47 UTC] nikcomestotalk at gmail dot com
That's why i raised the bug
(Float)"NANO"                
(Float)"INF"                 
(Float)"INFORMATION"
(Float) NAN   [Only this should give NAN, since it's not a string]

HHVM also faces the same problem
https://github.com/facebook/hhvm/issues/6986 
Fixed in 
https://github.com/facebook/hhvm/commit/e6abf022c3b32944ba0c861ca073fbfed9fc9be8
 [2016-10-17 13:48 UTC] cmb@php.net
I'm not sure if that qualifies as bug; simply ignoring
unrecognized trailing characters is normal behavior of float
conversion, see <https://3v4l.org/F18FJ> and even
<https://3v4l.org/dYHtG>. (I don't find this behavior particularly
useful, but we have it.)
 [2016-10-17 14:38 UTC] requinix@php.net
> simply ignoring unrecognized trailing characters is normal behavior
Which makes sense (sort of) when it's converting something which is recognizably a number.
To a human, "123abc" is formed of two parts ("123" and "abc") and getting a result of 123 makes sense because that's what the first part represents. But "nano" looks like just one part, and since it doesn't represent a number I think the result should be 0 - just like it would be with "mini" or "touch".

If (float)"Nan0" == NAN and (float)"Inf!nity" == INF then that'd be alright to me.
 [2016-10-17 17:17 UTC] nikcomestotalk at gmail dot com
-Status: Verified +Status: Closed
 [2016-10-17 17:17 UTC] nikcomestotalk at gmail dot com
I understand the complexity of this but are we in  mood of going strict data types in future.


(float)"123abc" should return "NAN"
(float)"information" should return "NAN" not "INF"
 [2016-10-17 17:24 UTC] requinix@php.net
-Status: Closed +Status: Verified
 [2016-10-17 17:24 UTC] requinix@php.net
Did you mean to close this?

> we in  mood of going strict data types in future
Not really, no. (float)"123abc" === 123.0 for sure, and (float)"information" === INF or 0.0 depending on what happens with this bug report.
 [2016-10-17 17:33 UTC] nikcomestotalk at gmail dot com
Status ? 
Not intentional, it somehow got changed
 [2016-10-18 17:15 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9f2ab75b1096b881ee97eb2b436763aa14c19635
Log: Fixed bug #73329 (Float)&quot;Nano&quot; == NAN
 [2016-10-18 17:15 UTC] ab@php.net
-Status: Verified +Status: Closed
 [2016-10-25 15:21 UTC] krakjoe@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9f2ab75b1096b881ee97eb2b436763aa14c19635
Log: Fixed bug #73329 (Float)&quot;Nano&quot; == NAN
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC