Using %t , %f for Real Numbers

Hi All ,
I am trying the following code :


 `timescale 10 ns / 1 ps
 module  top ;

   parameter d = 1.54345 ; // As RHS  is  real  no. ,  d  is  parameter  of  real type  

   initial begin
    $display("parameter d = %0f",d);
    $display("parameter d = %0t",d);
   end
 endmodule

The output I observe :
parameter d = 1.543450
parameter d = 15434

Since 0.1ps == 0.0001ns , real numbers are rounded to 4 decimal places .

Using %f / %0f we observe real nos. , hence we observe the entire real no. 1.54345

Using %t / %0t time precision of 1ps would be used ( as there is No explicit $timeformat defined ) ,


Section  22.7  of  LRM  says :  Parameter d retains its value no matter what timescale is in effect

However my expectation was that first the real no. would be rounded off to 4 decimal places i.e 1.5435 .
Then it would be scaled to time unit of 10ns i.e 15.435ns which is 15435ps .

Hence I expected 2nd display statement to be : parameter d = 15435 ( which is different than the output )

My 2nd question is regarding the rounding-off of real numbers .

What gets rounded-off and when does it occur ?

Like the parameter d isn’t rounded-off to 4 decimal places ( as observed in output via %f )

However had we used delay as : #d ;

**Will the delay first be rounded-off to 4 decimal places first i.e 1.5435 before calculating simulation time corresponding to the delay ?
**
i.e #d would then correspond to 15.435ns of delay ( scaled to time unit of 10ns )

In reply to MICRO_91:

Does this answer your question.

In reply to dave_59:

Hi Dave ,

Using the same explanation as per the other link :

d stores the real value 1.54345.

Without an explicit $timeformat , the default $timeformat would have :
(1) 1st argument i.e units_number as 1ps ( since it’s the smallest time precision argument )
(2) 2nd argument i.e precision_number as 0
(3) 3rd argument i.e suffix_string as null string i.e “”
(4) 4th argument i.e minimum_field_width as 20

%t would assume its value argument is in time units of 10ns ,
but the default $timeformat says to scale it back to 1ps, with 0 decimal places of precision.

1.54345 ( assuming in time unit of 10ns ) when converted to 1ps would be 15434.5

Using 0 decimal place of precision , shouldn’t it be scaled to 15435 ?

EDIT : There is No rounding-off in this code as there are No delay statements !!
In both display statements , d retains it’s value 1.54345

In reply to MICRO_91:

This has to do with inaccuracies when converting a decimal fraction to a binary fraction.

1.54345 is actually stored as

1.54344999999999998863131622783839702606201171875