Bug #65212 [Opn->Nab]: problem if pass in numeric string containing a float between 0 and 1
| From: | cmb@php.net | Date: | Mon, 07 Dec 2020 12:09:18 +0000 |
| Subject: | Bug #65212 [Opn->Nab]: problem if pass in numeric string containing a float between 0 and 1 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-230892@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65212&edit=1
ID: 65212
Updated by: cmb@php.net
Reported by: iam4webwork at hotmail dot com
Summary: problem if pass in numeric string containing a float
between 0 and 1
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: Irrelevant
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
That behaves as documented[1]:
| Any invalid characters in number are silently ignored. As of PHP
| 7.4.0 supplying any invalid characters is deprecated.
[1] <https://www.php.net/manual/en/function.base-convert.php#refsect1-function.base-convert-parameters>
Previous Comments:
------------------------------------------------------------------------
[2013-07-06 17:42:13] iam4webwork at hotmail dot com
_php_math_basetozval appears to be source of problem b/c while it mimics strtol,
unlike strtol it fails to adequately deal with '.' being an illegal character.
strtol disregards '.' and all subsequent input whereas _php_math_basetozval just
skips the '.' and processes the next character.
------------------------------------------------------------------------
[2013-07-06 08:59:10] iam4webwork at hotmail dot com
Description:
------------
If you pass to base_convert a numeric string like "0.5", to have it converted
from base 10 to base 16, PHP will interpret the input as decimal 5 and return
hexadecimal 5. I suspect that the problem lies internally in the logic of
_php_math_basetozval.
Test script:
---------------
var_dump(base_convert("0.5",10,16));
Expected result:
----------------
I expected PHP to return a zero just as printf("%x","0.5") and dexhex() do.
Actual result:
--------------
5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65212&edit=1