freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: Manual: Documented % operator weirdness
Date Thu, 13 Oct 2016 20:28:27 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae ed6531689 -> 3ccd9e4cf


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-gae
Commit: 3ccd9e4cfcfd13e4b392a7d9a8ef1f669fef649e
Parents: ed65316
Author: ddekany <ddekany@apache.org>
Authored: Thu Oct 13 22:28:00 2016 +0200
Committer: ddekany <ddekany@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}   &lt;#-- Prints 2 --&gt;
+${12.9 % 5} &lt;#-- Prints 2 --&gt;
+${12.1 % 5} &lt;#-- Prints 2 --&gt;
+
+${12 % 6}   &lt;#-- Prints 0 --&gt;
+${12 % 6.9} &lt;#-- Prints 0 --&gt;</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} &lt;#-- Prints -2 --&gt;
+${-12 % 5} &lt;#-- Prints -2 --&gt;
+${12 % -5} &lt;#-- Prints 2 --&gt;
+</programlisting>
         </section>
 
         <section xml:id="dgui_template_exp_comparison">


Mime
View raw message