electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

float to fixed


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> float to fixed
Author Message
bm_soe



Joined: 06 Jan 2004
Posts: 51


Post01 Dec 2005 17:34   

float to fixed


how can we convert floating point c prog to fixed point c program.
Back to top
Google
AdSense
Google Adsense




Post01 Dec 2005 17:34   

Ads




Back to top
yjkwon57



Joined: 31 Jul 2004
Posts: 221
Helped: 21


Post02 Dec 2005 3:28   

Re: float to fixed


Hi~~

Yes, you can. The most important thing is to keep the best precision allowed by the platform where you are going to process the fixed data. Normally, most processors provide the arithmetic operation extension capability. For example, a processor with 16-bit data bus width has an instruction to add or subtract with carry or borrow. After examining the range of the data to be processed, you will determine the number of bits to represent the data and where the binary point are to be located. I heard about some auto-scaling programs to do these things.

Bye~~~
Back to top
maui



Joined: 19 Nov 2004
Posts: 55
Helped: 5
Location: Melbourne Victoria Australia


Post02 Dec 2005 11:58   

Re: float to fixed


yjkwon57,

First, simply convert all the floats to char int or long int.
long int is best, as it allows you to retain more precision.

Next convert all maths to retain precision in fixed point.

Ie, multiply and add before devide, you might have to fiddle with the equations to do this.

Finally add scailing. To do this work out what your largest and smallest possible values are through the different steps in the program, and how many extra bits you dont use in your variables(probably long's), then add scailing (easiest is multiply by 2 using left shift opperator variable<<6).
scail up at the start and scail down to reach your result ensureing you still have correct maths.
check that your variables cant overflow or underflow.

This should do the trick

maui
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> float to fixed
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
float to fixed point conversion function (7)
fixed fract from float data (separation) on SHARC (2)
[H/F/S/S]Asking the second point fixed float data results. (1)
float net and float pin in netlist (2)
float???? (3)
Float or Fix (11)
float to char (8)
float to ascii (1)
float to ascii conversion (4)
fast float routine in c (2)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS