Bug #73329 [Ver]: (Float)"Nano" == NAN [Should return me 0]
Edit report at https://bugs.php.net/bug.php?id=73329&edit=1
ID: 73329
Updated by: requinix@php.net
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:
> 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.
Previous Comments:
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
[2016-10-17 11:27:49] requinix@php.net
https://3v4l.org/FPsXI
https://github.com/php/php-src/blob/6053987bc27e8dede37f437193a5cad448f99bce/Zend/zend_strtod.c#L2720
It checks for "inf/infinity/nan" but not for a \0 afterwards.
------------------------------------------------------------------------
[2016-10-17 10:59:22] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73329&edit=1
Thread (9 messages)