#41802 [Opn->Csd]: Float values are implicitly converted to int when using modulo operator
| From: | vrana@php.net | Date: | Thu, 16 Aug 2007 13:31:15 +0000 |
| Subject: | #41802 [Opn->Csd]: Float values are implicitly converted to int when using modulo operator | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969377424@lists.php.net to get a copy of this message | ||
ID: 41802
Updated by: vrana@php.net
Reported By: cosborne83 at hotmail dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Windows XP
PHP Version: 5.2.3
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
"Operands of modulus are converted to integers (by stripping the
decimal part) before processing. "
Previous Comments:
------------------------------------------------------------------------
[2007-06-25 14:35:25] tony2001@php.net
This is how it works in C, hence this is how it should work in PHP.
Reclassified as docu problem.
------------------------------------------------------------------------
[2007-06-25 14:18:36] cosborne83 at hotmail dot com
Description:
------------
When applying the % (modulo) operator to floats, the values are
implicitly converted to int, which causes problems in many instances.
This means that you can't use floats to store integer values larger
than the maximum int value if you wish to perform modulo operations.
Theis behaviour is also invalid since modulo is well defined on floats
as well as ints.
Reproduce code:
---------------
$m = 5000000000;
$n = 3.5;
// Integer modulo but with large int stored as float
print $m % 10;
print "\n";
// Non-integer modulo.
print $n % 1.5;
Expected result:
----------------
0
0.5
Actual result:
--------------
4
0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41802&edit=1