www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: integer division with float result

0ffh Wrote:
 Hrmm, probably int division and two casts would suffice, which
 might be reduced by the optimiser to just the division.

 this works only for for some cases

cast anyway. eg: int a = (int)(b / c) * 500; You either _need_ that cast, or you need the float math. Because the result will be different. Well, this example is probably naive, but I yet have to dig this thread more to find the counter-examples. Well, the thread went to discussing the overloading of the division operator, which is not my preference anyway.
 unless you have the compiler do type

granted these days. :) When I try to compile my programs with the optimizer disabled, it usually became 3 times bigger and basically stops working because it became a CPU hog. :) (well, this is not about a PC progs, but about the progs for MCUs, and this basically is not my fault but gcc/avr-libc's one, but the fact is that the prog became completely unusable without an optimization).
Nov 19 2007