I find this module for the addition of two Fixed Point Numbers. Manual for using this Module: https://opencores.org/project,verilog_fixed_point_math_library,manual
How to add -1.5 (or any negative real number) to 0.5(any real number)??
My problem is that: I know how to represent positive numbers in fixed point representation. But I don't know how to represent -1.5(or any negative real number), but I tried taking 2's complement of 1.5 and given as input, but it is not giving proper output.
Edit: I tried, what Wouter and entrepreneur said, but that too not working.
Edit: Added Testbench of module.
module qadd(
input [N-1:0] a,
input [N-1:0] b,
output [N-1:0] c
);
//Parameterized values
parameter Q = 15;
parameter N = 32;
reg [N-1:0] res;
assign c = res;
always @(a,b)
begin
//both negative
if(a[N-1] == 1 && b[N-1] == 1) begin
//sign
res[N-1] = 1;
//whole
res[N-2:0] = a[N-2:0] + b[N-2:0];
end
//both positive
else if(a[N-1] == 0 && b[N-1] == 0) begin
//sign
res[N-1] = 0;
//whole
res[N-2:0] = a[N-2:0] + b[N-2:0];
end
//subtract a-b
else if(a[N-1] == 0 && b[N-1] == 1) begin
//sign
if(a[N-2:0] > b[N-2:0])
res[N-1] = 1;
else
res[N-1] = 0;
//whole
res[N-2:0] = a[N-2:0] - b[N-2:0];
end
//subtract b-a
else begin
//sign
if(a[N-2:0] < b[N-2:0])
res[N-1] = 1;
else
res[N-1] = 0;
//whole
res[N-2:0] = b[N-2:0] - a[N-2:0];
end
end
endmodule
//Test Bench
module qadd_tf;
// Inputs
reg [32:0] a;
reg [32:0] b;
// Outputs
wire [32:0] c;
// Instantiate the Unit Under Test (UUT)
qadd #(16,33) uut (a, b, c);
initial begin
// Initialize Inputs
b[32]=1;
b[31:16]= 16'b00000000_00000001;
b[15:0] = 16'b10000000_00000000;
a[32]=0;
a[31:16]= 16'b00000000_00000000;
a[15:0] = 16'b10000000_00000000;
#100;
#100;
end
endmodule