integer division with float result

Stas Sergeev stsp at aknet.ru
Sun Nov 18 21:46:39 PST 2007


Bill Baxter Wrote:
> Comparing with dynamically typed languages like Python isn't useful
> because in Python a/2 can return an integer for if a==4 a float if a==5.
>   A statically typed language like D doesn't have that luxury.
Of course, but there is no problem to make the / op to
just always return float, or is there?

> Anyway, that said, I think it'd be nice to have / do float division, and 
> introduce another operator (like python's //) for truncated integer 
> division.
For what?
You either write:
int c = a / b;
or:
float c = a / b;
Both seem to perfectly express the intention, so
what is the new operator may be good for?
Currently, the later expression simply makes no
sense. I don't even think it is present in some code.
So I don't think there will be any confusion or the
compatibility breakage even.



More information about the Digitalmars-d mailing list