cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
211 Views
Registered: ‎10-17-2020

verilog hdl

i want to print single precision floating point number , can anyone suggest how to do it . i tried using %f , but i got the different value ? 

0 Kudos
3 Replies
Highlighted
Scholar
Scholar
126 Views
Registered: ‎09-16-2009

Please show us a more complete example of what's not working.  

This should work fine:

real a = 0.125;
initial
  $display( "Variable a is %f", a );

Regards,

Mark 

Highlighted
Visitor
Visitor
81 Views
Registered: ‎10-17-2020

In my code  i m storing result in out_im and out_re using assign statement ,here i added some part of code , these value i want to print as float

the output( m_axis_data_tdata[31:0]) is float and represented using 754 single precision floating point 


wire [31:0] out_re;
assign out_re = m_axis_data_tdata[31:0];

but when i m displaying using this display statement i m getting wrong value of float

$display($time, " %f", out_re);

i tried with using real  like

real out_r

assign out_r = out_re ;

$display($time, " %f", out_r);

it is giving error as out_re is of 32 bit cannot assign to out_r

i even tried this

$display($time, " %f", $bitstoreal(out_re));

but it is giving nan

 

please help !!

 

0 Kudos
Highlighted
Scholar
Scholar
39 Views
Registered: ‎09-16-2009

I think you want the $bitstoshortreal (and shortreal) for 32-bit single precision floats:

 

shortreal pi = 3.14;
bits [ 31 : 0 ] pi_bits;
initial
begin
  pi_bits = $shortrealtobits( pi );
  $display( "PI ~= %0f = 0x%0x bits = %0f", pi, pi_bits, $bitstoshortreal( pi_bits ) );
end

 

Disclosure, I never use these functions, so I may have something wrong.  But this should get you closer.

Regards,

Mark

0 Kudos