Dealing with Unisigned 64bit Integers
Posted by: swedishchef (---.bb.sky.com)
Date: July 27, 2021 07:21PM

Hiya to all..

I have a web app that utilises MySQL as the DB back-end. To keep it simple, it has a single table called testbigint and has only 1 field called testval and is set to BigInt(20) - Unsigned and holds the value returned from the MySQL Function uuid_short() - according to the MySQL document it generates a unsigned (see [mariadb.com] for details).

Anyways, with my hosting (IONOS), when I insert the value that is generated from UUID_SHORT() it returned the following value: 10331511505513676677

So using the following lines of code
$bigval = 10331511505513676677;
var_dump($bigval);

Now examining this value via var_dump() it has now converted the number into a float and a loss of precision will follow, for completeness - var_dump() returns 1.0331511505514E+19

According to PHP documentation, PHP is unable to handle unsigned 64bit integers, but how can $bigval be converted into a string

Also, I am using a 64bit version of WampServer

Thanks in advance

Options: ReplyQuote
Re: Dealing with Unisigned 64bit Integers
Posted by: Otomatic (Moderator)
Date: July 28, 2021 04:09PM

Hi,

See Type juggling - Type Casting

See also BCMath Arbitrary Precision Mathematics

------------------------------------------------------------------------------------------------------------
Wampserver 3.2.6 32 bit - Apache 2.4.49 - PHP 8.0.9…5.6.40 - MySQL 5.7.35 - MariaDB 10.5.12/10.6.4
Wampserver 3.2.6 64 bit - Apache 2.4.49 - PHP 8.0.9…5.6.40 - MySQL 5.7.35/8.0.26 - MariaDB 10.5.12/10.6.4
PhPMyadmin 5.1.1 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote
Re: Dealing with Unisigned 64bit Integers
Posted by: RiggsFolly (Moderator)
Date: July 28, 2021 09:55PM

Simple.

MAX_INT (64bit) is 9223372036854775807 and 10331511505513676677 is greater than that so its converted to something that can hold that number.

echo PHP_INT_MAX . PHP_EOL;
echo '10331511505513676677'.PHP_EOL;

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.2.5 32bit & 64bit)
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.