|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-11-04 16:14 UTC] aidevelopment at gmail dot com
Description:
------------
Despite having PHP_INT_MAX set to 8 bytes, It is impossible to have an int greater than 1000000000000000000000000000000000000000000000000000000000000000.
8 Byte, or 64 bit maximum should be 1111111111111111111111111111111111111111111111111111111111111111.
In my included example, it is clear that when attempting to increase the value above(by adding 1), simply nothing happens.
Attempting to assign a variable to a number greater than the above number produces unpredictable results.
Reproduce code:
---------------
<?php
echo "Int Size = ".PHP_INT_SIZE." bytes.<br>";
$status = 0x7FFFFFFFFFFFFFFF;
for($i=0;$i<=4;$i++)
{
printf ("status = '%b'<br>", $status);
$status++;
}
?>
Expected result:
----------------
Int Size = 8 bytes.
status = '111111111111111111111111111111111111111111111111111111111111111'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000001'
status = '1000000000000000000000000000000000000000000000000000000000000010'
status = '1000000000000000000000000000000000000000000000000000000000000011'
Actual result:
--------------
Int Size = 8 bytes.
status = '111111111111111111111111111111111111111111111111111111111111111'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000000'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 04:00:02 2025 UTC |
Hi Jani, Thanks for the update. Please, allow me to clarify my last post. With the information you've given, we know the 64th bit (far left), is reserved for sign. With a simple two line script, we can see that 0 = positive, therefore 1 = negative. //determine positive vs. negative (observe far left bit). $a=5; printf("a = '%b'", $a); The example below will show the difference between actual expected result when increasing integers past the maximum value of an unsigned int. //set a equal to the max $a = 0x7FFFFFFFFFFFFFFF; //add one $a++; //Expecting a variable wrap here. e.x. $a = -0x7FFFFFFFFFFFFFFF //Actual result is $a = negative 0 printf("a = '%b'", $a); //add one $a++; //Given a is now actually equal to negative 0 //Expecting a = 1; //Actual result is $a = negative 0 (unchanged). printf("a = '%b'" ,$a); I would appreciate if you would explain how giving the incorrect answer to a simple mathematical formula (x+1) is not a bug. If this is in fact a bug, please re-open, reassign and/or recategorize this bug appropriately. Thanks! Cheers! Steve