I am trying to round off the sc_time to the nearest 10 nanoseconds. /
is overloaded so it is possible to divide two sc_time
. *
is also overloaded with a sc_time
and a double
value. For this code, I am getting 6
and not 10
.
#include <iostream>
#include "systemc.h"
SC_MODULE(X)
{
SC_CTOR(X)
{
SC_THREAD(a);
}
void a()
{
sc_time t(6, SC_NS);
sc_time t1(10, SC_NS);
double v = (t / t1) *10;
std::cout << "sc_time update:/ " << v << "\n";
}
};
int sc_main( int , char* [] )
{
sc_clock clock;
X x("x");
sc_start(1000, SC_NS);
cout << "Program completed" << endl;
return 0;
}
快速浏览一下sc_time
标头https://github.com/systemc/systemc-2.3/blob/master/src/sysc/kernel/sc_time.h表示它使用双精度进行数学sc_time
,因此sc_time
6/10*10==6
并不奇怪6/10*10==6
您需要添加一个明确的回合:
double v = round(t / t1) *10;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.