Oh Dear

Bill Baxter wbaxter at gmail.com
Sun Jul 12 18:28:56 PDT 2009


On Sun, Jul 12, 2009 at 5:36 PM, Walter
Bright<newshound1 at digitalmars.com> wrote:
> Rainer Deyke wrote:
>>
>> Walter Bright wrote:
>>>
>>> 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:
>>
>> The PEP is wrong (which underlines the need for accurate documentation,
>> I guess).  Integer division in Python uses floor division instead of
>> truncated division, and to the best of my knowledge has always used
>> floor division.  This is the result of a deliberate choice.  Floor
>> division is usually technically superior to truncated division
>>
>> The operator for integer division in Python has recently changed from
>> '/' to '//', but Python still has an integer division operator and this
>> operator still uses floor division.
>
> If Python always used floor division, why did it add a // operator that does
> exactly the same thing as / ?
>
>
> http://www.python.org/doc/2.2.3/whatsnew/node7.html
>

The new // forces integer division.  / now means float division always.

1 // 2   --> 0
1 / 2   --> 0.5

They first introduced // as a synonym for / so people could start
switching over to it, then they changed the behavior of / later.
Python's good at staged introductions of major changes like that.
Makes life a lot easier for developers to keep up.

--bb



More information about the Digitalmars-d mailing list