Received: from mail.proteosys.com ([213.139.130.197]) by nummer-3.proteosys with Microsoft SMTPSVC(6.0.3790.3959); Thu, 8 Nov 2007 11:24:18 +0100 Received: by mail.proteosys.com (8.13.8/8.13.4) with ESMTP id lA8AO4qf006831 for ; Thu, 8 Nov 2007 11:24:04 +0100 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id lA8AIK8P013431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Nov 2007 11:18:20 +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 lA89VT2P004836; Thu, 8 Nov 2007 11:19:12 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 15.0) with spool id 190572 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Thu, 8 Nov 2007 11:19:12 +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 lA8AJCQE009384 for ; Thu, 8 Nov 2007 11:19:12 +0100 Received: from mailer2.silverstroke.com (mailer1.silverstroke.com [195.124.154.146]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id lA8AHqU6013019 for ; Thu, 8 Nov 2007 11:17:56 +0100 Received: from localhost (localhost [127.0.0.1]) by mailer2.silverstroke.com (Silverstroke mailrelay) with ESMTP id 748F485EC7 for ; Thu, 8 Nov 2007 11:18:55 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at silverstroke.com Received: from mailer2.silverstroke.com ([127.0.0.1]) by localhost (mailer2.silverstroke.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sktX0DaTwtZa for ; Thu, 8 Nov 2007 11:18:55 +0100 (CET) Received: from s-yellow.net.silverstroke.de (s-yellow.net.silverstroke.de [172.16.20.5]) by mailer2.silverstroke.com (Silverstroke mailrelay) with ESMTP id 3E3BB85EC6 for ; Thu, 8 Nov 2007 11:18:55 +0100 (CET) X-MimeOLE: Produced By Microsoft Exchange V6.0.6619.12 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Bug in \int_div_truncate_raw:nn Thread-Index: Acgh7xLEIoe9K6q6TNepnMHk2V9BKQAADWFg References: <9343542E664B894484613D106D7D3F5F84AAE9@s-yellow.net.silverstroke.de> A<20071108090815.GA3380@irwin.vpn.uni-freiburg.de> Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by listserv.uni-heidelberg.de id lA8AJCQE009385 Message-ID: <9343542E664B894484613D106D7D3F5F84AAEC@s-yellow.net.silverstroke.de> Date: Thu, 8 Nov 2007 11:18:55 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Jonathan Sauer Subject: Re: Bug in \int_div_truncate_raw:nn To: LATEX-L@LISTSERV.UNI-HEIDELBERG.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 10:24:18.0508 (UTC) FILETIME=[852AF8C0:01C821F1] Status: R X-Status: X-Keywords: X-UID: 5072 Hello, > > 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. :-(( Indeed not. Does anybody know why it was implemented in the first place? It differs from \divide's behaviour, but surely there was a good reason for implementing it. > > 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 Thanks! Seems like I used parentheses in a "better safe than sorry" way and forgot basic math while at it. > > This seems to work better. > > No: -2/2 = -2 Dang! Please add "for positive numbers" in my statement above ;-) (note to self: Add unit tests for negative numbers) > 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. It looks like that is the only way to be safe. > Yours sincerely > Heiko Jonathan