Bug #62729 [Ana->Nab]: fmod() and "modulo" operator do not work are not consistent with big int.

From: Date: Wed, 31 Aug 2016 21:27:50 +0000
Subject: Bug #62729 [Ana->Nab]: fmod() and "modulo" operator do not work are not consistent with big int.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203709@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62729&edit=1 ID: 62729 Updated by: cmb@php.net Reported by: arnaud at wixiweb dot fr Summary: fmod() and "modulo" operator do not work are not consistent with big int. -Status: Analyzed +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Linux / Windows PHP Version: 5.4.5 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: As of PHP 7.0.0 true 64bit support for Windows is officially available, so this issue is supposed to be solved. The difference in example 3 has been already explained by Rasmus. The difference in example 4 is due to the numerator being not an int at all, but rather got converted to float before the modulus operation, see <https://3v4l.org/pK8C8>. Previous Comments: ------------------------------------------------------------------------ [2012-08-03 02:06:10] rasmus@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#203709) next »