I am trying to understand the return type of $realtime via the following example from LRM Section 20.3.3 :
`timescale 10 ns / 1 ps
module top ;
logic set;
parameter p = 1.54345 ; // Value different than mentioned in LRM
initial begin
#p set = 0;
$display($realtime,,"set = 0");
#p set = 1;
$display($realtime,," set = 1");
end
endmodule
I have the following understanding :
(1) First simulation time corresponding to individual delays is calculated .
p corresponds to 1.54345 x 10ns i.e 15.4345ns
There is No need to round-off as there are already 4 decimal places after the decimal point
1st assignment occurs at 15.4345ns ,
2nd assignment occurs at 15.4345ns + 15.4345ns i.e 30.8690ns
(2) Value returned by $realtime is a real number scaled to the time unit of the module i.e 10ns .
i.e The value returned by $realtime when multiplied by time unit of 10ns would give us the same simulation time of 15.4345ns and 30.8690ns.
Therefore the expected output was :
1.5434 set = 0
3.0869 set = 1
However the output I observe is :
1.5435 set = 0
3.087 set = 1
It seems that the value returned by $realtime is being rounded-off from 1.54345 to 1.5435
Since we already rounded-off to 4 decimal places in step 2 , why is it that it’s being rounded-off again in the output ?
Any pointers / suggestions would be helpful .
Thanks