integer division with float result

Bill Baxter dnewsgroup at billbaxter.com
Sun Nov 18 21:51:27 PST 2007


Stas Sergeev wrote:
> 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?

Which flavor of division is being used here?

void do_something(int x) { ... }
void do_something(float x) { ... }

do_something(a/b);

--bb



More information about the Digitalmars-d mailing list