| Author |
Message |
bm_soe
Joined: 06 Jan 2004 Posts: 51
|
01 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

|
01 Dec 2005 17:34 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
yjkwon57
Joined: 31 Jul 2004 Posts: 221 Helped: 21
|
02 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
|
02 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 |
|
 |