Bug #64350 [Opn->Nab]: fmod returning wrong values for negative dividends
| From: | rasmus@php.net | Date: | Mon, 04 Mar 2013 15:59:14 +0000 |
| Subject: | Bug #64350 [Opn->Nab]: fmod returning wrong values for negative dividends | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-177576@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64350&edit=1
ID: 64350
Updated by: rasmus@php.net
Reported by: spam at michaelburri dot ch
Summary: fmod returning wrong values for negative dividends
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: OS X 10.8.2 (12C3012)
PHP Version: 5.4Git-2013-03-04 (Git)
Block user comment: N
Private report: N
New Comment:
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));
}
Previous Comments:
------------------------------------------------------------------------
[2013-03-04 15:37:42] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64350&edit=1