php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27064 The mod function of % does not return the same results of fmod.
Submitted: 2004-01-27 15:35 UTC Modified: 2004-01-27 15:58 UTC
From: ngaugler at ngworld dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.4 OS: FreeBSD 4.9 / Linux 2.4.23
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ngaugler at ngworld dot net
New email:
PHP Version: OS:

 

 [2004-01-27 15:35 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-27 15:54 UTC] sniper@php.net
Yes, you're dealing with floats. Of course fmod() works.
(try doing 'var_dump(2190988683);'...)


 [2004-01-27 15:58 UTC] ngaugler at ngworld dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC