Edit report at https://bugs.php.net/bug.php?id=62729&edit=1
ID: 62729 Updated by: ras...@php.net Reported by: arnaud at wixiweb dot fr Summary: fmod() and "modulo" operator do not work are not consistent with big int. -Status: Open +Status: Analyzed Type: Bug Package: Scripting Engine problem Operating System: Linux / Windows PHP Version: 5.4.5 Block user comment: N Private report: N New Comment: Note that longs on 64-bit Windows are still only 32 bits. A long on 64-bit Linux is 64 bits. So, to work with large values like that you will need to use something like bcmod() fmod(x,y) returns x - n * y where n is the quotient of x / y floor'ed and converted to an integer which isn't always going to give you the same result as x % y. If you are working with integers use %. If you are working with doubles, use fmod(). And keep in mind that these are signed so you don't have the whole 32/64 bit space. The upper bit is the sign. Given this I am not sure I see a bug here. You are mostly comparing 32-bit to 64-bit here. Previous Comments: ------------------------------------------------------------------------ [2012-08-03 00:15:33] arnaud at wixiweb dot fr Description: ------------ fmod() and "modulo" operator do not work are not consistent with big int. Moreover, the results change between windows(PHP5.4) to linux(PHP5.3) See the test script for more informations Test script: --------------- // On Windows64 with PHP 5.4 // Example 1 var_dump(fmod(12345678901234567, 62)); // float(52) var_dump(12345678901234567 % 62); // int(20) // Example 2 var_dump(fmod(9999999999999999111, 62)); // float(18) var_dump(9999999999999999111 % 62); // int(0) // On Linux64 with PHP 5.3 // Example 3 var_dump(fmod(12345678901234567, 62)); // float(52) var_dump(12345678901234567 % 62); // int(51) // Example 4 var_dump(fmod(9999999999999999111, 62)); // float(18) var_dump(9999999999999999111 % 62); // int(-60) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62729&edit=1