Use the output of a module inside a class (including task (generator)

In reply to saketa:

I did not calculate all the details, but I got
sine_out = 2.500735
with your code and the same value with using the C-library subroutine sin form the math-package.
This value is definitely not only the offset.

BTW this is the code I using the sin c-lib:
module sv_ams_sin_voltage_gen(output real sine_out);
parameter sampling_time = 5;
const real pi = 3.1416;
real time_us, time_s ;
bit sampling_clock;
real freq = 20;
real offset = 2.5;
real ampl = 2.5;

import “DPI-C” pure function real sin(real);

always sampling_clock = #(sampling_time) ~sampling_clock;

always @(sampling_clock) begin
time_us = $time/1000;
time_s = time_us/1000000;
end

assign sine_out = offset + (ampl * sin(2pifreq));
initial
$display(“sine_out = %0f”, offset + (ampl * sin(2pifreq)));

endmodule