php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64350 fmod returning wrong values for negative dividends
Submitted: 2013-03-04 15:37 UTC Modified: 2013-03-04 15:59 UTC
From: spam at michaelburri dot ch Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.4Git-2013-03-04 (Git) OS: OS X 10.8.2 (12C3012)
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: spam at michaelburri dot ch
New email:
PHP Version: OS:

 

 [2013-03-04 15:37 UTC] spam at michaelburri dot ch
Description:
------------
The fmod(dividend, divisor) function returns wrong values for negative dividends 
that are smaller than the divisor.

For example -0.8 mod 6 => -1 * 6 + 5.2, so the result of the modulo (= remainder) 
is 5.2.

Test script:
---------------
<?php
  echo fmod(-0.8, 6); //Should return 5.2, but returns -0.8
?>

Expected result:
----------------
5.2

Actual result:
--------------
-0.8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-04 15:59 UTC] rasmus@php.net
Nope, it is correct. Read up on fmod and negative operands and you can try this 
simple C program:

void main(int argc, char *argv[]) {
  printf("%f", fmod(-0.8,6));
}
 [2013-03-04 15:59 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 04:01:29 2024 UTC