You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2016/12/06 22:30:08 UTC
[13/24] incubator-freemarker git commit: Manual: Documented %
operator weirdness
Manual: Documented % operator weirdness
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/3ccd9e4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/3ccd9e4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/3ccd9e4c
Branch: refs/heads/2.3
Commit: 3ccd9e4cfcfd13e4b392a7d9a8ef1f669fef649e
Parents: ed65316
Author: ddekany <dd...@apache.org>
Authored: Thu Oct 13 22:28:00 2016 +0200
Committer: ddekany <dd...@apache.org>
Committed: Thu Oct 13 22:28:00 2016 +0200
----------------------------------------------------------------------
src/manual/en_US/book.xml | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/3ccd9e4c/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index ce9b08f..38741d3 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -3286,7 +3286,8 @@ Slicing with right-unlimited ranges:
</listitem>
<listitem>
- <para>Modulus (remainder): <literal>%</literal></para>
+ <para>Modulus (remainder) of integer operands:
+ <literal>%</literal></para>
</listitem>
</itemizedlist>
@@ -3323,8 +3324,6 @@ ${12 % 10}</programlisting>
<programlisting role="template">${3 + "5"}</programlisting>
- <para>will output this:</para>
-
<programlisting role="output">35</programlisting>
<para>Generally, FreeMarker never converts a string to a number
@@ -3353,6 +3352,26 @@ ${-1.999?int}</programlisting>
1
-1
-1</programlisting>
+
+ <para>Due to historical reasons, the <literal>%</literal> operator
+ works by first truncating the operands to an integer number, and
+ then returning the remainder of the division:</para>
+
+ <programlisting role="template">${12 % 5} <#-- Prints 2 -->
+${12.9 % 5} <#-- Prints 2 -->
+${12.1 % 5} <#-- Prints 2 -->
+
+${12 % 6} <#-- Prints 0 -->
+${12 % 6.9} <#-- Prints 0 --></programlisting>
+
+ <para>The sign of the result of <literal>%</literal> is the same as
+ the sign of the left hand operand, and its absolute value is the
+ same as if both operands where positive:</para>
+
+ <programlisting role="template">${-12 % -5} <#-- Prints -2 -->
+${-12 % 5} <#-- Prints -2 -->
+${12 % -5} <#-- Prints 2 -->
+</programlisting>
</section>
<section xml:id="dgui_template_exp_comparison">