proposed syntax change

Marianne Gagnon auria.mg at gmail.com
Thu Aug 6 16:01:39 PDT 2009


Paul D. Anderson Wrote:

> I was browsing the Python spec yesterday and came across this interesting and useful syntax:
> 
> "/" (one slash) means floating point division, e.g. 5/2 = 2.5 even though 5 and 2 are integers
> 
> "//" (two slashes) means integer (floor) division, e.g. 5.0//2.0 = 2.0 even though 5.0 and 2.0 are floats.
> 
> I've always been a little troubled by the standard division operator being dependent on the types of the operands. (I understand the need for it, I just didn't like it much.) Now here is an elegant (IMHO) solution.
> 

But, in your example it's still dependant on operand types. Division is performed very differently on integers and on IEEE754 floats. So even with your proposal there would be implicit casts. Also you give example 5.0//2.0 = 2.0. Isn't // integer division? But it gives a truncated float? Oh, still more type inference.



More information about the Digitalmars-d mailing list