php 64bit integer overflow differs from Java implmention -
I am trying to implement the random class of Java in PHP and after several hours I came to know that PHP is a Different values give Java 2 times the 64-bit multiplication time.
PHP
echo (160577175182 * 25214903917);
returns
9101091335015235584
in a Java applet
Drawerring ("Java:" + (160577175182 L * 25214903917 L), 10, 10);
returns
java: 9101091335015183990
Interestingly, if you put it in the programmer mode, So it also produces 91010 9 1335015183990.
25214903917 Java Random Magic Number 0x5DEECE66D
160577175182 is a test seed value
I know the resultant number is greater than the 64 bit number and therefore the result of both Are wrong I need to be able to replicate the result of Java in php.
I tested some classes in extended arithmetic java, and reached the following conclusion:
The result of PHP is consistent with multiplying on ineffective input as integer, but then converting the result into a 64-bit floating point.
In the following results, all numbers are in hexadecimal because it is easy to see what is happening.
Full product db7e4d92597bf73676
Product round IEEE 754 64-bit floating point to DB7E4D92597 BF 80000
Java result is 7e4d92597bf73676, less than Less 64 bits of full product.
The PHP product is 7e4d92597bf80000, the bits of the integer value of dual conversion of at least significant 64 product.
I'm not a PHP expert. Is PHP an expanded integer data type or library? To get the right result, at least 64 bits should be removed from the product without changing the non-floating point.
Comments
Post a Comment