php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42418 Strange behaviour of modulus function
Submitted: 2007-08-24 19:45 UTC Modified: 2007-08-27 05:56 UTC
From: onyjgyjz at trashmail dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.3 OS: WinXP
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: onyjgyjz at trashmail dot net
New email:
PHP Version: OS:

 

 [2007-08-24 19:45 UTC] onyjgyjz at trashmail dot net
Description:
------------
Somehow the modulus operator does not behave as expected on some special numbers.(maybe integer overflow or something like that?)

Php-version i used:
PHP 5.2.3 (cli) (built: May 31 2007 09:37:22)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

Reproduce code:
---------------
$a=11213214321;
echo $a % 2;

Expected result:
----------------
Output of: 1

Actual result:
--------------
Output of: -1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-26 16:49 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

11213214321 overflows an integer and is converted into a negative 
number. The modulus operation is then performed on a negative value, 
hence the -1 return value.
 [2007-08-27 05:56 UTC] onyjgyjz at trashmail dot net
Shouldn't it return an error, if an integer was overflowed?
(like this "Division through Zero" error)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC