- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to multiply two fractional numbers of 42 bits in verilog. I am using the fixed point (Q12.30). Now my result is wrong.
part of my code: module my_name (out,Clk) input Clk; output reg signed [83:0] out; //(Q24.60) reg signed [41:0] in1; //(Q12.30) reg signed [41:0] in2; //(Q12.30) always @(posedge Clk) out <= in1 * in2; endmodule for example if in1=-2 & in2=-1.89652 then out=3.79304 , but my result is -15956.351736 !!! in modelsim: -2 is 42'b111111111110_000000000000000000000000000000 -1.89652 is 42'b111111111110_00011010011111011010111100000 -15956.351736 is 111111111100000110101011_101001011111010010100010000000000000000000000000000000000000 (WRONG) plz tell me how multiply two fractional numbers. thanks.Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks as though you have implemented an unsigned multiply rather than a signed multiply. It is treating -2 as 4094.0 and -1.89652 as 4094.10348
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Besides wrong result sign, how can the compiler know that you are meaning fractional numbers? Obviously the result has to be scaled by a factor of 2^12, you should also apply saturation logic to avoid overflow to wrong result when cutting 12 bits on the left.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page