1

How can I represent floating point numbers in Verilog?

I am trying to use following code to do floating point addition but I am seeing integer as a output:

real r1,r2,r3;

initial begin
    r1 = 1.1;
    r2 = 1.2;
    r3 = r1+ r2;
    $display("Print the output %b", r3);
end

1 Answer 1

1

%b indicates that a result should be print as binary. If you want to display a float number, you should use %e indicator.

$display("Print the output %e", r3);

Result before the change:

Print the output 00000000000000000000000000000010

and after:

Print the output 2.300000e+00
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Qiu, Is there any way to print the output in 32bit binary form?
@naveenkumar: here you can find available format indicators.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.