Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 63B6E200BD3 for ; Tue, 6 Dec 2016 23:30:02 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 60E34160B1B; Tue, 6 Dec 2016 22:30:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B281B160B29 for ; Tue, 6 Dec 2016 23:30:01 +0100 (CET) Received: (qmail 30064 invoked by uid 500); 6 Dec 2016 22:30:00 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 30036 invoked by uid 99); 6 Dec 2016 22:30:00 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2016 22:30:00 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 55C2618BB5E for ; Tue, 6 Dec 2016 22:30:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id lCJ27lYldQIb for ; Tue, 6 Dec 2016 22:29:59 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 2495F5FDAC for ; Tue, 6 Dec 2016 22:29:57 +0000 (UTC) Received: (qmail 29255 invoked by uid 99); 6 Dec 2016 22:29:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2016 22:29:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BFECCF214C; Tue, 6 Dec 2016 22:29:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Tue, 06 Dec 2016 22:30:08 -0000 Message-Id: <69cb11298d184b8eb6d9d38e624bcb3e@git.apache.org> In-Reply-To: <05bcaa7349b249bca60d129188d4364f@git.apache.org> References: <05bcaa7349b249bca60d129188d4364f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/24] incubator-freemarker git commit: Manual: Documented % operator weirdness archived-at: Tue, 06 Dec 2016 22:30:02 -0000 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 Authored: Thu Oct 13 22:28:00 2016 +0200 Committer: ddekany 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: - Modulus (remainder): % + Modulus (remainder) of integer operands: + % @@ -3323,8 +3324,6 @@ ${12 % 10} ${3 + "5"} - will output this: - 35 Generally, FreeMarker never converts a string to a number @@ -3353,6 +3352,26 @@ ${-1.999?int} 1 -1 -1 + + Due to historical reasons, the % operator + works by first truncating the operands to an integer number, and + then returning the remainder of the division: + + ${12 % 5} <#-- Prints 2 --> +${12.9 % 5} <#-- Prints 2 --> +${12.1 % 5} <#-- Prints 2 --> + +${12 % 6} <#-- Prints 0 --> +${12 % 6.9} <#-- Prints 0 --> + + The sign of the result of % is the same as + the sign of the left hand operand, and its absolute value is the + same as if both operands where positive: + + ${-12 % -5} <#-- Prints -2 --> +${-12 % 5} <#-- Prints -2 --> +${12 % -5} <#-- Prints 2 --> +