Andes Workshop

It is currently Thu Mar 28, 2024 11:23 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: 沒定義type的浮點數用double來處理
PostPosted: Fri Nov 23, 2012 5:17 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
下面有一個例子
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;


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group