Bug #50630 [Opn->Bgs]: Modulo on strings/floats won't work on huge numbers
| From: | tony2001@php.net | Date: | Tue, 08 Jun 2010 13:11:19 +0000 |
| Subject: | Bug #50630 [Opn->Bgs]: Modulo on strings/floats won't work on huge numbers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151211@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=50630&edit=1
ID: 50630
Updated by: tony2001@php.net
Reported by: bananen-joe at bananen-joe dot de
Summary: Modulo on strings/floats won't work on huge numbers
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: win32 only - Windows XP SP3
PHP Version: 5.3.1
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2010-01-06 06:46:18] federico dot lebron at gmail dot com
The size of 9999999990 is larger than PHP_INT_MAX, so when converting to
integer (since you asked for modulo, and it gets converted to integer),
you're getting undefined behavior, as per
http://php.net/manual/en/language.types.integer.php
. No warnings or
notices will be triggered in such a case.
Internally (and on this machine, with PHP compiled as 32 bit),
strtol("9999999990", NULL, 10) is being called for the string case,
which is 2147483647. This is noted in the intval function's
documentation, so it's expected. For the float case, (long) (unsigned
long) (long long int) 9999999990 is being casted, which is 1410065398,
but this is undefined behavior.
------------------------------------------------------------------------
[2010-01-01 22:25:24] bananen-joe at bananen-joe dot de
Description:
------------
If you use the modulo operator on huge numbers (which cannot be
converted into integers) you get a strange result.
Even not error is reported.
Reproduce code:
---------------
error_reporting(E_ALL);
$number = '9999999990';
echo "$number % 10 = ", $number % 10, "<br>";
$number = 9999999990;
echo "$number % 10 = ", $number % 10, "<br>";
$number = '99990';
echo "$number % 10 = ", $number % 10, "<br>";
$number = (float) 99990;
echo "$number % 10 = ", $number % 10, "<br>";
Expected result:
----------------
9999999990 % 10 = 0 (or even an error notice/warning)
9999999990 % 10 = 0 (or even an error notice/warning)
99990 % 10 = 0
99990 % 10 = 0
Actual result:
--------------
9999999990 % 10 = 7
9999999990 % 10 = 8
99990 % 10 = 0
99990 % 10 = 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=50630&edit=1