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 do fixed point multiply C code?

Status
Not open for further replies.

boeysue

Full Member level 3
Joined
Dec 23, 2004
Messages
188
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Activity points
1,523
Is the following correct??

x.data=a.data *b.data;
x.wordlen=a.wordlen+b.wordlen;
x.fractlen=a.fractlen + b.fractlen;

??


Bcz My answer seems wrong...so help....~~
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
Maybe yes, maybe no. Need more info.
Please post a small, complete program, and tell us what answer you expected and what answer you got.
 

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
892
Helped
175
Reputation
350
Reaction score
51
Trophy points
1,308
Activity points
6,830
Your code is correct if
type of x.data is correct
What I maen is "if type of a.data and b.data is same lets say unsigned int (32 bits)
then type of x.data must be long long unsigned int (64 bits)
Hope this help
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
nand_gates said:
What I maen is "if type of a.data and b.data is same lets say unsigned int (32 bits)
then type of x.data must be long long unsigned int (64 bits)

That wouldn't work. You have to cast at least one of the multiplicands to the larger integer type *before* multiplying them.
 

boeysue

Full Member level 3
Joined
Dec 23, 2004
Messages
188
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Activity points
1,523
mmm..
What I want is a general equation for all Q.format ....such as [16 18],[16 0],..[16 15],..........Is there any information about it?thanks for that.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top