Andes Workshop

It is currently Fri Mar 29, 2024 3:16 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: 解決浮點數運算code size較大的問題
PostPosted: Fri Nov 23, 2012 5:12 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
如果程式裡用到浮點數(float)運算,
在沒有FPU的cpu中,
toolchain會將浮點數運算的compiler加進來,
造成code size較大。

解決辦法:
將浮點運算改用整數計算,
例如乘0.2就改為除以5。
舉例來說,
area=a*b*3.14
則我們可以用分數的算法
area=(a*b*314)/100

為了避免overflow,我們可以先化簡,乘起來的數字比較小,
比方說,上述式子改成area=(a*b*157)/50。
或者定義area變數為long long,就可以有足夠大的空間。


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 10 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