Oh Dear

Rainer Deyke rainerd at eldwood.com
Sun Jul 12 03:09:26 PDT 2009


Walter Bright wrote:
> If there's any question about it, you can do a quick test and check what
> the compiler generates with obj2asm. If it wasn't doing things
> correctly, you bet people would have noticed by now. A divide that
> doesn't work is going to be very, very obvious.

Actually I suspect that integer division with negative values is rare
enough that a problem might escape notice for some time.

Python uses floor division, which is 99% of the time the type of
division I want.  C++ uses truncating division, which is almost never
what I want.  D does not specify the type of division used, although if
it uses IDIV then it uses truncating division.  Result: in C++ (and D) I
use my own library function to perform floor division instead of relying
on the built-in division operator.  Signed integer division never gets
tested for negative values.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list