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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 08:01:24 2019 UTC