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
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: 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

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: Thu Mar 28 09:01:26 2024 UTC