Detecting inadvertent use of integer division

Nick Sabalausky a at a.a
Tue Dec 15 14:17:42 PST 2009


"KennyTM~" <kennytm at gmail.com> wrote in message 
news:hg90tu$22od$1 at digitalmars.com...
> On Dec 16, 09 05:14, bearophile wrote:
>> Don:
>>
>>> Bob Jones:
>>>> double y = a / double(b);
>>
>>> OK, I misunderstood you. You're completely right. At least my proposal
>>> won't let them slip through silently. I don't think we can do anything
>>> else without silently breaking C compatibility.
>>
>> A silly idea that may keep C compatibility and avoid that cast: instead 
>> of an integer division operator it can be added a operator that always 
>> performs a floating point division, as:
>> int a = 5, b = 7;
>> double y = a \\ b;
>> (I don't like that much, Pascal is better here).
>>
>> Bye,
>> bearophile
>
> Just introduce real fdiv(real, real)  (or /fdiv/) if this is the solution. 
> Works right now without changing the language.

Reserving the only division operator for intdiv-only for the sake of C 
compatibility would be terrible design.





More information about the Digitalmars-d mailing list