php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3593 % (mod or modulo) not behaving correctly
Submitted: 2000-02-23 16:38 UTC Modified: 2000-05-26 12:00 UTC
From: shannon dot behrens at clearink dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Beta 4 Patch Level 1 OS: FreeBSD and Linux
Private report: No CVE-ID: None
 [2000-02-23 16:38 UTC] shannon dot behrens at clearink dot com
I noticed while writing a script that:

	print (-1%12);

produces:

	-1

when the correct behavior is to produce:

	11

Although -1 is "kindof" correct, 11 is the more correct response.  It is also the response produced in both Perl and Python.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-26 12:00 UTC] hholzgra at cvs dot php dot net
from the manual:

Table 7-1. Arithmetic Operators
...
$a % $b | Modulus | Remainder of $a divided by $b.
...

$b * (int)($a/$b) + ($a%$b) == $a should be true in any case

and thats the way it is in c and php

if perl and python do different let them be
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC