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
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: shannon dot behrens at clearink dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 19:01:35 2025 UTC