integer division with float result

Stas Sergeev stsp at aknet.ru
Mon Nov 19 22:15:08 PST 2007


renoX Wrote:
> In a statically typed language, the issue is which float type do you use 
> for (int / int)?
> For accuracy, it ought to be one with biggest precision, but it's also 
> the slowest, and can be non-portable (x86 has 80-bit float, other CPU do 
> not)
I don't think this is really a problem.
For example, doing an integer calculus, you can
get an overflow, because the compiler does not
promote ints to long-longs for you. So if you have
a very large values, you have to explicitly notify
the compiler by doing casts. OTOH, it does promote
the shorts to ints for you, when needed.
Same is here: the float can be used by default, and
if you really need a hight precision, then you have
to resort to an explicit casts, I think.



More information about the Digitalmars-d mailing list