Regarding Time precision

My recent threads have made me realize that I need to brush-up concepts of timeunit and timeprecision .


LRM  Section 22.7  ::  " The time_precision argument specifies how delay values are rounded before being used in simulation "

[ 1 ] I have doubt related to " Delays are rounded to real numbers with n decimal places "

(a) For `timescale 1 ns / 1 ps , Delays are rounded to real numbers with three decimal places—or precise to within one thousandth of a nanosecond—because the time_precision argument is “1 ps,” or one thousandth of a nanosecond.

 As  1ps  is  0.001ns  delays  are  rounded  to  3  decimal  places .

(b) For `timescale 10 us / 100 ns , as 100ns is 0.1 us would the real numbers be rounded to 1 decimal place ?

Does the value specified in the timeunit and timeprecision i.e 10 and 100 in (b) contribute to how many decimal place the real number gets rounded to ?

[ 2 ] I then tried a similar code from LRM Section 22.7 with the timescale and timeunit changed :: EDA_LINK

In the O/P why is $realtime scaled to precision value of 100ns i.e 0.1us ?

 I  expected  that  the  real  numbers  be  rounded  to  1  decimal  place  so  parameter  d  should  have  been  scaled to  15.5us  , 

 Delay  of  #1.1499  be  scaled  to  11.5us  ,  delay  of  #1.1551  be  scaled  to  11.6us

In reply to hisingh:

There is fixed point decimal place notation, and then there is conversions of fixed point decimal numbers to their binary representation. You should read Why 0.1 Does Not Exist In Floating-Point

In reply to dave_59:

I had missed out on few key points in the LRM . Turns out the LRM does answer my questions .

For [2] %t is based on default $timeformat , which has the 1st argument ’ units_number ’ " as the smallest precision of all the `timescale directives in the source "

Hence %t is scaled to time_precision of 100ns .

Now I am confused about using $realtime without a format-specifier .

I have a new code :: EDA_$realtime

The $realtime within module tb2 returns values as per my expectations i.e

Real numbers are rounded to 3 decimal places due to time_precision of 1ps .

However why is it that $realtime returns integers 1 , 2 , 3 , 4 instead of real numbers for tb1 ?

As per LRM Section 20.3.3 example I was expecting real numbers as :: 1.1 , 2.223 , 3.335 and 4.447 respectively .

In reply to hisingh:

The problem with the timescale compiler directive is that is does not change the timescale in the middle of module. So your first timescale directive only effects the second module tb2.

The timeunt statement can be placed at the beginning of a module.

module  tb1 ;
  timeunit 1ns / 1ps;