user3185902
user3185902

Reputation: 117

Non-integer values in verilog

Is there a way to store and compute non-integer values in verilog, (say x = 5/2 = 2.5 ). Can I compute and store 2.5 in x defined above?

Upvotes: 0

Views: 2024

Answers (1)

Qiu
Qiu

Reputation: 5751

Yes, you can use real registers to store real values, i.e.:

real float; // a register to store real value 

Usually it's a 64-bit wide data type that stores floating-point values. But not all Verilog operators can be used with expression involving real numbers and real registers. Concatenations, modulus operator, case equality, bit-wise operators, reduction operators shift operators, bit-selects and part-selects on real type variables are not allowed.

Simple example:

module ecample;
real r;

initial begin 
  r = 123456e-3;
  $display("r=%f",r); // r = 123.456000
  #20 r = r / 2;
  $display("r=%f",r); // r = 61.728000
  $finish; 
end 
endmodule 

Upvotes: 1

Related Questions