Received: from mail.proteosys.com ([213.139.130.197]) by nummer-3.proteosys with Microsoft SMTPSVC(6.0.3790.3959); Thu, 8 Nov 2007 10:17:18 +0100 Received: by mail.proteosys.com (8.13.8/8.13.4) with ESMTP id lA89H3tR027610 for ; Thu, 8 Nov 2007 10:17:03 +0100 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id lA898Qia003992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Nov 2007 10:08:26 +0100 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id lA7N1DnL027114; Thu, 8 Nov 2007 10:08:23 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 15.0) with spool id 190280 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Thu, 8 Nov 2007 10:08:23 +0100 Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id lA898NHQ021662 for ; Thu, 8 Nov 2007 10:08:23 +0100 Received: from atlas.informatik.uni-freiburg.de (atlas.informatik.uni-freiburg.de [132.230.150.3]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id lA897FqU010227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 8 Nov 2007 10:07:19 +0100 Received: from remote239-40.home.uni-freiburg.de ([132.230.239.40] helo=irwin.vpn.uni-freiburg.de) by atlas.informatik.uni-freiburg.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1Iq3N4-0004BD-LP for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Thu, 08 Nov 2007 10:08:18 +0100 Received: by irwin.vpn.uni-freiburg.de (Postfix, from userid 500) id 45AE679C7; Thu, 8 Nov 2007 10:08:16 +0100 (CET) Mail-Followup-To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE References: <9343542E664B894484613D106D7D3F5F84AAE9@s-yellow.net.silverstroke.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Auto-Whitelist: Message-ID: <20071108090815.GA3380@irwin.vpn.uni-freiburg.de> Date: Thu, 8 Nov 2007 10:08:16 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Heiko Oberdiek Subject: Re: Bug in \int_div_truncate_raw:nn To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: <9343542E664B894484613D106D7D3F5F84AAE9@s-yellow.net.silverstroke.de> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-ProteoSys-SPAM-Score: -2.599 () BAYES_00 X-Scanned-By: MIMEDefang 2.57 on 213.139.130.197 Return-Path: owner-latex-l@LISTSERV.UNI-HEIDELBERG.DE X-OriginalArrivalTime: 08 Nov 2007 09:17:18.0362 (UTC) FILETIME=[28F95FA0:01C821E8] Status: R X-Status: X-Keywords: X-UID: 5071 On Thu, Nov 08, 2007 at 09:30:06AM +0100, Jonathan Sauer wrote: > I hope this is the right place for this. > > Macro \int_div_truncate_raw:nn is defined in file l3int as: > > \def_new:Npn \int_div_truncate_raw:nn #1#2 { > \int_eval:n{ (2*#1 - #2) / (2* #2) } > } > > If #1 is zero and #2 is two, this macro does not expand to zero, > as one would expect (0 / 2 = 0), but to -1 (since eTeX rounds > negative numbers by negating them, rounding the positive number > and negating the result. See function "quotient" in etex.ch). This eTeX-rounding does not make life easier. :-(( > Also, if #2 is an expression (i.e. 1+1), the calculation is not > performed correctly, since #2 (and #1) is not surrounded by ( and ). > (I am not sure if this can happen, or if the parameters are always > evaluated beforehand) > > In my code, I use (to divide #1 by #2): > > \numexpr((((#1)+((#2)/2))/(#2))-1)\relax With less parentheses: \numexpr (#1+(#2)/2)/(#2)-1\relax > This seems to work better. No: -2/2 = -2 Also both solutions have the disadvantage, that intermediate results may cause an arithmetic overflow. As result the accepted number range is limited unnecessarily. Therefore I have choosen a more complicate route in package `intcalc' by a case switch for zero, positive and negative numbers. Yours sincerely Heiko