Andes Workshop
http://forum.andestech.com/

沒定義type的浮點數用double來處理
http://forum.andestech.com/viewtopic.php?f=25&t=642
Page 1 of 1

Author:  cindy [ Fri Nov 23, 2012 5:17 pm ]
Post subject:  沒定義type的浮點數用double來處理

下面有一個例子
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;

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/