svn: /phpdoc/en/trunk/language/ operators.xml
| From: | Adam Harvey | Date: | Mon, 08 Nov 2010 10:05:39 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ operators.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-7391@lists.php.net to get a copy of this message | ||
aharvey Mon, 08 Nov 2010 10:05:39 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=305195
Log:
Expanded the discussion of the modulus operator's handling of negative operands
per doc bug #53208.
Bug: http://bugs.php.net/53208 (Assigned) Modulo does not
calc right (C99 not mathematical correct)
Changed paths:
U phpdoc/en/trunk/language/operators.xml
Modified: phpdoc/en/trunk/language/operators.xml
===================================================================
--- phpdoc/en/trunk/language/operators.xml 2010-11-08 09:37:17 UTC (rev 305194)
+++ phpdoc/en/trunk/language/operators.xml 2010-11-08 10:05:39 UTC (rev 305195)
@@ -297,12 +297,25 @@
Operands of modulus are converted to integers (by stripping the decimal
part) before processing.
</simpara>
- <note>
- <simpara>
- Remainder <literal>$a % $b</literal> is negative for negative
- <literal>$a</literal>.
- </simpara>
- </note>
+ <para>
+ The result of the modulus operator <literal>%</literal> has the same sign
+ as the dividend — that is, the result of <literal>$a % $b</literal>
+ will have the same sign as <varname>$a</varname>. For example:
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
+<?php
+
+echo (5 % 3)."\n"; // prints 2
+echo (5 % -3)."\n"; // prints 2
+echo (-5 % 3)."\n"; // prints -2
+echo (-5 % -3)."\n"; // prints -2
+
+?>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
<simpara>
See also the manual page on
<link linkend="ref.math">Math functions</link>.