Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert floating point to fixed point c program ?

Status
Not open for further replies.

bm_soe

Member level 1
Joined
Jan 6, 2004
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
170
float to fixed

how can we convert floating point c prog to fixed point c program.
 

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

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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top