php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39610 Number of return Modular_arithmetic is negative..
Submitted: 2006-11-23 22:59 UTC Modified: 2006-11-24 13:05 UTC
From: ocracy at msn dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.4.4 OS: windows
Private report: No CVE-ID: None
 [2006-11-23 22:59 UTC] ocracy at msn dot com
Description:
------------
Number of return Modular_arithmetic must be positive in general but i tryed high nubmer  like(2^30++) in Modular_arithmetic, PHP gave me negative nubmer...

example:  x=2^31, y=x%20, y = negative in PHP

Reproduce code:
---------------
<?php
$number = 31;
$pow = pow(2,$number);
$random = rand(10,50);
echo ($pow%$random);
?>

Expected result:
----------------
Negative numbers..
Like
-6
-38
-44
..
..

Actual result:
--------------
nubmer of return will be positive..

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-23 23:11 UTC] tony2001@php.net
# php -r 'var_dump(pow(2,31));' is greater than PHP_INT_MAX, so it cannot be represented as positive integer when casted to int.
Hence "Note: Remainder $a % $b is negative for negative $a."
http://www.php.net/manual/en/language.operators.arithmetic.php
 [2006-11-24 13:05 UTC] ocracy at msn dot com
i beg your pardon.. i acted inattentive, i didnt pay attention to PHP_INT_MAX and nubmer of float
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 23:01:33 2025 UTC