Content-Transfer-Encoding: |
8bit |
Sender: |
|
Subject: |
|
From: |
|
Date: |
Thu, 8 Nov 2007 11:18:55 +0100 |
Content-Type: |
text/plain; charset="us-ascii" |
MIME-Version: |
1.0 |
Reply-To: |
|
Parts/Attachments: |
|
|
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 <[log in to unmask]>
Jonathan
|
|
|