Bug #76884 [Nab->Opn]: base_convert restore data not equal origin data
| From: | aston dot seal at gmail dot com | Date: | Sat, 15 Sep 2018 03:34:15 +0000 |
| Subject: | Bug #76884 [Nab->Opn]: base_convert restore data not equal origin data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217063@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76884&edit=1
ID: 76884
User updated by: aston dot seal at gmail dot com
Reported by: aston dot seal at gmail dot com
Summary: base_convert restore data not equal origin data
-Status: Not a bug
+Status: Open
Type: Bug
-Package: *General Issues
+Package: Math related
Operating System: centos 7.4
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
change package
Previous Comments:
------------------------------------------------------------------------
[2018-09-15 03:33:33] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
> Warning: base_convert() may lose precision on large numbers due to properties related to the
> internal "double" or
> "float" type used. Please see the Floating point numbers section in the manual for
> more specific information and
> limitations.
You're trying to generate a unique identifier. There are better methods.
------------------------------------------------------------------------
[2018-09-15 03:24:50] aston dot seal at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.base-convert
---
PHP Version : PHP 7.2.10 (cli) (built: Sep 11 2018 10:09:51) ( NTS )
when I using base_convert to make a order id for my system, I found it restore my data isn't
correct, is it a bug ?
origin_data always not equal recovery_data
Test script:
---------------
$a = '10010'.sprintf('%02d',mt_rand(0,99)).str_pad(str_replace('.',
'', microtime(TRUE)), 14, 0, STR_PAD_RIGHT);
echo 'origin_data : '.$a;
echo '<br>';
$b = base_convert($a, 10,36);
echo 'convert_data : '.$b;
echo '<br>';
echo 'recovery_data : '.base_convert($b, 36,10);
Expected result:
----------------
origin_data : 100106615369813329847
convert_data : l4k9ti8ikb4cg
recovery_data : 100106615369813329847
Actual result:
--------------
origin_data : 100106615369813329847
convert_data : l4k9ti8ikb4cg
recovery_data : 100106615369813328882
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76884&edit=1