#27064 [Bgs]: The mod function of % does not return the same results of fmod.

From: Date: Tue, 27 Jan 2004 20:58:29 +0000
Subject: #27064 [Bgs]: The mod function of % does not return the same results of fmod.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-53996@lists.php.net to get a copy of this message
ID: 27064 User updated by: ngaugler at ngworld dot net Reported By: ngaugler at ngworld dot net Status: Bogus Bug Type: Math related Operating System: FreeBSD 4.9 / Linux 2.4.23 PHP Version: 4.3.4 New Comment: Ok, so where in the documentation does it explain that you can't use % on floats? I love how PHP just doesn't work as expected, yet Perl, MySQL, you name it, all have no problems. Previous Comments: ------------------------------------------------------------------------ [2004-01-27 15:54:22] sniper@php.net Yes, you're dealing with floats. Of course fmod() works. (try doing 'var_dump(2190988683);'...) ------------------------------------------------------------------------ [2004-01-27 15:35:06] ngaugler at ngworld dot net Description: ------------ When performing a % (mod) function on two numbers, PHP returns negative values when it should not. Example: PHP: (2190988683 % 3) returns -1 fmod(2190988683,3) returns 0 Perl: (2190988683 % 3) returns 0 Reproduce code: --------------- <? echo "(2190988683 % 3) = " . (2190988683 % 3). "<br>\n"; echo "fmod(2190988683,3) = " . fmod(2190988683,3) . "<br>\n"; ?> Expected result: ---------------- (2190988683 % 3) = 0 fmod(2190988683,3) = 0 Actual result: -------------- (2190988683 % 3) = -1 fmod(2190988683,3) = 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27064&edit=1

« previous php.bugs (#53996) next »