Not getting expected value while using real and realtime data type

Hi,

I want to calculate the bandwidth.
so I calculated the duration between the start time and end time like below

realtime start1,end1, duration;
real bandwidth;
int total bits;

start1 = $realtime;
end1 = $realtime;
duration = end1- start1;
bandwidth = total bits/duration;

expected bandwidth is 412 / 2367 = 0.174059
but am getting 174.059

please help me with this.

Is all of the code shown contained in the same module?

Can you display all the intermediate values?

Can you how us exactly how you are displaying the values (i.e. using what format?)

Hi deve …
Yes . all codes are in single module(inside fork join)
$display("start1 = %0t end1 = %0t duration = %0t “,start1,end1,duration);
$display(” total bits = %0d bandwidth = %f ",total_bits,bandwidth);

result:
start1 = 4734
end1 = 7101
duration = 2367
total bits = 412
bandwidth = 174.059

after changing the timescale from 1ns/1ps to 1ps/1ps its working fine. may I know the reason

Without seeing all of your code, it is hard to give you a good answer, but using %t is probably obscuring the issue. Without using $timeformat %t assumes the argument’s value is in the current time unit and then scales it to the global time precision (smallest precision of all designs).

I suggest you normalize the start and end values to *1ps. Also display your normalised values using %f.

module top;
  timeunit 1ps/1ps;
  realtime start1,end1, duration;
  real bandwidth;
  int total_bits=412;

initial begin 
  fork
    #4734ps start1 = $realtime/1ps;
    #7101ps end1 = $realtime/1ps;
  join
  duration = end1- start1;
  bandwidth = total_bits/duration;
  $display("start1 = %t end1 = %t duration = %t ",start1,end1,duration); 
  $display("start1 = %f end1 = %f duration = %f ",start1,end1,duration); 
  $display("%10.5f",bandwidth);
end
endmodule