ID: 47246
Comment by: helpmepro1 at gmail dot com
Reported By: helpmepro1 at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: linux
PHP Version: 5.2.8
New Comment:
on windows it works like this:
var_dump(-4738698913) = float(-4738698913)
so this number is float
A decbin 43814 SIMPLE = 1010101100100110
B decbin -4738698913 NOT WORKING =
11100101100011010011000101011111
C decbin 4738698913 SIMPLE =
11010011100101100111010100001
D decbin abs -4738698913 WORKING =
11010011100101100111010100001
E decbin ~abs -4738698913 NOT WORKING =
11100101100011010011000101011110
F decbin ~abs -1738698913 WORKING =
10011000010111011000111101011110
php version 4.4.4
Previous Comments:
------------------------------------------------------------------------
[2009-01-29 21:17:04] helpmepro1 at gmail dot com
Description:
------------
the problem is doing bitwise operations with large numbers like larger
then 28 bit.
when i do
negative bitwise operation "~" to 4738698913
in binary
11010011100101100111010100001{29bit}
the number becomes binary
10000000000000000000000000000000{32bit}
expected:
11100101100011010011000101011110
Reproduce code:
---------------
<TEXTAREA STYLE="height:98%;width:98%">
<?php
//
//I think I found out the solution by using GMP function.
//Code:
function gxor($a,$b)
{
$a=gmp_init("$a",10);
$b=gmp_init("$b",10);
return gmp_strval (gmp_xor ($a, $b),10);
}
echo "gxor(-5799680607,167160) = ".gxor(-5799680607,167160)."\n";
echo " as expected -5799843495 \n";
echo " -5799680607^167160 = " .(-5799680607^167160)."\n";
echo " wrong result \n\n";
echo "var_dump(-4738698913) = ";
var_dump(-4738698913);
echo "so this number is float\n\n";
echo "A decbin 43814 SIMPLE =
".decbin(43814)."\n\n"; //a
echo "B decbin -4738698913 NOT WORKING =
".decbin(-4738698913)."\n\n"; //b
echo "C decbin 4738698913 SIMPLE =
".decbin(4738698913)."\n\n";
echo "D decbin abs -4738698913 WORKING =
".decbin(abs(-4738698913))."\n\n";
echo "E decbin ~abs -4738698913 NOT WORKING =
".decbin(~abs(-4738698913))."\n\n";
echo "F decbin ~abs -1738698913 WORKING =
".decbin(~abs(-1738698913))."\n\n";
echo "G decbin ~ -4738698913 64bit expected result:
1111111111111111111111111111111011100101100011010011000101011110\n";
echo "H the 64bit bitwise not is from windows calc.exe\n\n";
echo "from the B and G example i can deduce that php takes the left
side of 64 bit integer instead of the right and returns it as 32 bit
(just a guess)\n\n";
// 1111111111111111111111111111111011100101100011010011000101011110
echo "php version ".PHP_VERSION;
echo "\n";
echo `cat /proc/version`;
echo "\n";
echo `cat /proc/cpuinfo`;
echo "\n";
?>
</TEXTAREA>
Expected result:
----------------
gxor(-5799680607,167160) = -5799843495
as expected -5799843495
-5799680607^167160 = -2147316488
wrong result
var_dump(-4738698913) = float(-4738698913)
so this number is float
A decbin 43814 SIMPLE = 1010101100100110
B decbin -4738698913 NOT WORKING =
10000000000000000000000000000000
C decbin 4738698913 SIMPLE =
11010011100101100111010100001
D decbin abs -4738698913 WORKING =
11010011100101100111010100001
E decbin ~abs -4738698913 NOT WORKING =
1111111111111111111111111111111
F decbin ~abs -1738698913 WORKING =
10011000010111011000111101011110
G decbin ~ -4738698913 64bit expected result:
1111111111111111111111111111111011100101100011010011000101011110
H the 64bit bitwise not is from windows calc.exe
from the B and G example i can deduce that php takes the left side of
64 bit integer instead of the right and returns it as 32 bit (just a
guess)
Actual result:
--------------
php version 5.1.6
Linux version 2.6.18-92.1.18.el5PAE ([email protected])
(gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Wed Nov 12
10:02:30 EST 2008
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Xeon(R) CPU E5405 @ 2.00GHz
stepping : 6
cpu MHz : 1995.120
cache size : 6144 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm
constant_tsc pni monitor ds_cpl vmx tm2 cx16 xtpr lahf_lm
bogomips : 3992.34
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47246&edit=1