|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45688 64bit unsigned integers, or provide a workaround.
Submitted: 2008-08-02 14:14 UTC Modified: 2021-06-08 14:08 UTC
Avg. Score:4.4 ± 0.9
Reproduced:5 of 7 (71.4%)
Same Version:3 (60.0%)
Same OS:4 (80.0%)
From: andy at haveland dot com Assigned: cmb (profile)
Status: Wont fix Package: *Programming Data Structures
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-08-02 14:14 UTC] andy at haveland dot com
I've had a look at some bogus bug reports on unsigned integers and rounding precision, and understand the issues and reasons but want to add my voice to request better integer support. bcmaths is overkill for simple bit operations.

I'm trying to use php to process thousands of random 64-bit ids supplied in decimal and half have the high bit set.
As they are keys in a database mapped to hierarchical directories, accuracy, speed and repeatability is a big issue. Renaming to 63 bit ids is not an option!

You may consider this as a bogus request, but I think lack of unsigned support is a serious issue.

Any bit operations that touch the high bit turn to mush if set, and limits php to 31 or 63 bit program!

If perl can deal correctly with this, then shouldn't php be able to as well?


Reproduce code:
    $id = 11791849344837931437;
    print  "\$id = $id\n";
    printf("\$id = 0x%x (%20u)\n", $id, $id);
    f(($id & 0xf000000000000000) >> 60);

    $idhi= $id >> 32;
    $idlo= $id & 0xffffffff;

    f2($idhi, $idlo);

function f($id) {
    printf ("f(\$id) = 0x%x (%20u)\n", $id, $id);

function f2($idhi, $idlo) {
    printf ("\$idhi = 0x%x (%20u)\n", $idhi, $idhi);
    printf ("\$idlo = 0x%x (%20u)\n", $idlo, $idlo);

(Perl code is practically identical, apart from s/function/sub/ and param passing)

Expected result:
# perl
$id = 11791849344837931437
$id = 0xa3a51080d3fcd1ad (11791849344837931437)
f($id) = 0xa3a51080d3fcd1ad (11791849344837931437)
f($id) = 0xa (                  10)
$idhi = 0xa3a51080 (          2745503872)
$idlo = 0xd3fcd1ad (          3556561325)

Actual result:
# php showbug.php
$id = 1.1791849344838E+19
$id = 0xa3a51080d3fcd000 (11791849344837931008)
f($id) = 0xa3a51080d3fcd000 (11791849344837931008)
f($id) = 0xfffffffffffffffa (18446744073709551610)
$idhi = 0xffffffffa3a51080 (18446744072160088192)
$idlo = 0xd3fcd000 (          3556560896)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 01:23 UTC]
This RFC would deal with this, indirectly:
 [2015-01-09 01:23 UTC]
-Package: Feature/Change Request +Package: *Programming Data Structures -Operating System: Linux +Operating System: * -PHP Version: 5.2.6 +PHP Version: *
 [2015-01-09 03:01 UTC] andy at haveland dot com
Wow, 6.4 years elapsed!

Thanks for the interesting link, it would be good to see it integrated into php.

I think I ended up using perl to restructure the directory tree from
/xxx/xxx/xxx/xxxxxxxxxxx.jpg to
Three levels was way overkill for just half a million images.
 [2021-06-08 14:08 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-06-08 14:08 UTC]
While I'd like to see Bigint support as well, I don't think that
RFC would satisfy your request, since it would support arbitrary
precision numbers, and while the implementation would likely be
more efficient than BC, it would still be way less efficient than

I don't see, however, much point in implementing support for
unsigned ints; the implementation complexity would be in the same
order of magnitude as for Bigint if implemented as native type,
but for a way smaller gain.  Also note that a lot of 64bit
unsigned operations can be already done without resorting to BC or
GMP numbers.

> Wow, 6.4 years elapsed!

Oops, it happened again.  And I predict that it will happen over
and over again until somebody pursues the RFC process[1].

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 05:03:37 2021 UTC