下面有一個例子 1) 在 mainflow.c line #30, 有一段 float 的運算 abc=((uint32)(abb-aaa)*ba); 2) 在algo.c line #52 也有一段 float 的運算 bb=cc*0.2;
他們發現加入 1) 的 float 運算會增加一些 code size. 然後又加入 2) 的浮點運算又增加了 code size. ------------------------------
解答 According to C99 6.4.4.2 point 4: "An unsuffixed floating constant has type double. If suffixed...." (C99 is C programming languague standard which is adopted by most C compiler)
So the statement "bb=cc*0.2; " will use double-precision operation.
If you would like to have floating constant with 'float' type, you should do explicitly casting or suffix it with the letter 'f'.
bb = cc * (float)0.2; bb = cc * 0.2f;
|