A 64 bit integer for PHP
thegeek misses a 64 bit integer for PHP (German), since he uses a bitmask with more then 32 options. Here's a proposal, how to deal with this problem by splitting a float into two integers:
<?php define("BIGINT_DIVIDER", 0x7fffffff + 1); function split2Int(&$upper, &$lower, $value) { $lower = intval($value % BIGINT_DIVIDER); $upper = intval(($value - $lower) / BIGINT_DIVIDER); } function bigInt2float($upper, $lower) { return $upper * BIGINT_DIVIDER + $lower; } ?>
split2Int puts the upper 32 bits into $upper and the lower 32 bits into $lower. Binary operations can now be performed on both the ints. Afterwards, the result in converted to a float using bigInt2float(). I also wrapped up this stuff into a little class. You can download it here.
Comment by Martin
March 4, 2006 - 18:20
Another solution is the bigint pecl package:
http://pecl.php.net/package/big_int