%description: SimTime: check overflow detection %activity: #define TRY(code) \ EV << #code << " -> "; \ try { \ code; EV << "OK\n"; \ } catch (std::exception& e) { \ EV << e.what() << endl; \ } SimTime t,t2; double dmax = floor(SimTime::getMaxTime().dbl()); ASSERT(SimTime::getScaleExp()==-12); // these should be OK TRY( t=dmax; ) TRY( t=-dmax; ) // assignment from double TRY( t=dmax+1.0; ) TRY( t=-dmax-1.0; ) TRY( t=1e100; ) TRY( t=-1e100; ) // simtime + simtime TRY( t=dmax; t2=1; t=t+t2; ) TRY( t=-dmax; t2=-1; t=t+t2; ) TRY( t=dmax; t2=dmax; t=t+t2; ) TRY( t=-dmax; t2=-dmax; t=t+t2; ) // simtime - simtime TRY( t=dmax; t2=-1; t=t-t2; ) TRY( t=-dmax; t2=1; t=t-t2; ) TRY( t=dmax; t2=-dmax; t=t-t2; ) TRY( t=-dmax; t2=dmax; t=t-t2; ) // simtime * double, simtime / double TRY( t=1; t = t * 1e100; ) TRY( t=1; t = t * -1e100; ) TRY( t=1; t = t / 1e-100; ) TRY( t=1; t = t / -1e-100; ) // note: other operations all work via the ones above EV << ".\n"; %contains-regex: stdout t=dmax; -> OK t=-dmax; -> OK t=dmax\+1\.0; -> Cannot convert.* t=-dmax-1\.0; -> Cannot convert.* t=1e100; -> Cannot convert.* t=-1e100; -> Cannot convert.* t=dmax; t2=1; t=t\+t2; -> simtime_t overflow.* t=-dmax; t2=-1; t=t\+t2; -> simtime_t overflow.* t=dmax; t2=dmax; t=t\+t2; -> simtime_t overflow.* t=-dmax; t2=-dmax; t=t\+t2; -> simtime_t overflow.* t=dmax; t2=-1; t=t-t2; -> simtime_t overflow.* t=-dmax; t2=1; t=t-t2; -> simtime_t overflow.* t=dmax; t2=-dmax; t=t-t2; -> simtime_t overflow.* t=-dmax; t2=dmax; t=t-t2; -> simtime_t overflow.* t=1; t = t \* 1e100; -> Cannot convert.* t=1; t = t \* -1e100; -> Cannot convert.* t=1; t = t / 1e-100; -> Cannot convert.* t=1; t = t / -1e-100; -> Cannot convert.* \.