Promotion rules ... why no float?

Daniel Kozak via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 6 08:43:22 PDT 2016


Dne 6.9.2016 v 17:26 Steven Schveighoffer via Digitalmars-d napsal(a):

> On 9/6/16 11:00 AM, Sai wrote:
>> Thanks for the replies.
>>
>> I tend to use a lot of float math (robotics and automation) so I almost
>> always want float output in case of division. And once in a while I bump
>> into this issue.
>>
>> I am wondering what are the best ways to work around it.
>>
>>     float c = a / b;     // a and b could be integers.
>>
>> Some solutions:
>>
>>     float c = cast!float(a) / b;
>
> auto c = float(a) / b;
>
> -Steve

another solution is use own function for div operation

auto c = div(a,b);


More information about the Digitalmars-d mailing list