## LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

 Options: Use Forum View Use Proportional Font Show Text Part by Default Condense Mail Headers Message: [<< First] [< Prev] [Next >] [Last >>] Topic: [<< First] [< Prev] [Next >] [Last >>] Author: [<< First] [< Prev] [Next >] [Last >>]

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
`