10-17-2020 09:20 AM
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 ?
10-19-2020 07:21 AM
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 );
10-25-2020 12:43 AM
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
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 !!
10-26-2020 08:31 AM - edited 10-26-2020 08:32 AM
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.