Bug #73329 [Ver]: (Float)"Nano" == NAN [Should return me 0]

From: Date: Mon, 17 Oct 2016 17:33:57 +0000
Subject: Bug #73329 [Ver]: (Float)"Nano" == NAN [Should return me 0]
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204879@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73329&edit=1 ID: 73329 User updated by: nikcomestotalk at gmail dot com Reported by: nikcomestotalk at gmail dot com Summary: (Float)"Nano" == NAN [Should return me 0] Status: Verified Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: 7.0.12 Block user comment: N Private report: N New Comment: Status ? Not intentional, it somehow got changed Previous Comments: ------------------------------------------------------------------------ [2016-10-17 17:24:33] 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:17:05] 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 14:38:06] 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 13:48:54] 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 12:47:11] 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 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=73329 -- Edit this bug report at https://bugs.php.net/bug.php?id=73329&edit=1

« previous php.bugs (#204879) next »