M.L. wrote: >> On Mon, Jul 6, 2009 at 7:07 PM, sergio masci >> wrote: = >> And forgetting about optimisation completely, what about promoting >> integers to floats? >> >> e.g. >> =A0 =A0 =A0 =A0float =A0 x; >> =A0 =A0 =A0 =A0int =A0 =A0 y, z; >> >> =A0 =A0 =A0 =A0x =3D y / z; >> >> here a decent language / compiler could see that the result result >> needs to be a float and promot y and z to floats and perform a >> floating point division. > = > IIRC the C type is undefined ... Not sure what you mean by "undefined"; the expression "y / z" in the code above has a result type of int (both values are of type int). > ... - in any case and you should typecast it to float. > > x =3D (float)(y/z); This isn't changing anything. This cast is implicit already in Sergio's code. The division is still executed as integer division, then the result is cast to float. This is exactly what the first code above does. I suspect you mean something like = x =3D (float)y / z; which explicitly casts y to float, then by the promotion rules implicitly casts y and z to double and executes the division as double division, then casts the result down to float. (IIRC... I don't do a lot of implicit casting of floats; I actually almost never use float.) Gerhard -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist