Oh Dear

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jul 12 15:45:52 PDT 2009


Walter Bright wrote:
> bearophile wrote:
>> Walter Bright:
>>> The result of / depends on which version of Python you're using:
>>> http://www.python.org/doc/2.2.3/whatsnew/node7.html
>>
>> I have used Python 2.6, and the numbers I have shown you are correct 
>> for Python 3.1 too.
>> I don't like how the % behaves in C when there can be negative numbers.
> 
> According to the python pep, the integer / divide semantics changed from 
> "C" style to match what the floating point / does. While this makes 
> sense for a language that is typeless, it doesn't work for D because:
> 
> 1. it would cause D code to silently produce different results than the 
> corresponding C/C++ code. This is extremely important, as I guarantee 
> that when someone new tries porting existing C code to D, and it doesn't 
> work, their conclusion will not be "perhaps I should recode the / 
> expression", it will be "D sux". Note that there is no way the compiler 
> could issue a warning about this as it cannot determine a dependency on 
> the rounding method.

But C gives the implementation leeway to define '/' as they find fit. 
This is useless because it makes it difficult to write portable code. We 
must improve on that.

> 2. it is slower than the current method.

We want something well-defined. I agree to adopt the semantics of IDIV 
but we must understand that those might be slower on other machines.


Andrei



More information about the Digitalmars-d mailing list