31 #ifndef __adevs_time_h_
32 #define __adevs_time_h_
39 template <
class T>
inline T adevs_inf();
41 template <
class T>
inline T adevs_zero();
43 template <
class T>
inline T adevs_sentinel();
53 template<
class T =
double>
struct Time
60 Time(T t = adevs_zero<T>(),
unsigned int c = 0):t(t),c(c){}
85 if (t2.t == 0)
return Time(t,t2.c+c);
86 else return Time(t+t2.t,0);
102 return (t == t2.t && c == t2.c);
107 return !(*
this == t2);
112 return (t < t2.t || (t == t2.t && c < t2.c));
114 bool operator<=(
const Time& t2)
const
116 return (*
this == t2 || *
this < t2);
118 bool operator>(
const Time& t2)
const
120 return !(*
this <= t2);
122 bool operator>=(
const Time& t2)
const
124 return !(*
this < t2);
141 inline int fcmp(
double x1,
double x2,
double epsilon)
160 frexp(fabs(x1) > fabs(x2) ? x1 : x2, &exponent);
171 delta = ldexp(epsilon, exponent);
173 difference = x1 - x2;
175 if (difference > delta)
177 else if (difference < -delta)
210 const double_fcmp& operator=(
double rhs)
219 bool operator<(
double rhs)
const
223 bool operator<(
const double_fcmp& rhs)
const
227 bool operator<=(
const double_fcmp& rhs)
const
231 bool operator>(
const double_fcmp& rhs)
const
235 bool operator>=(
const double_fcmp& rhs)
const
239 bool operator==(
double rhs)
const
243 bool operator==(
const double_fcmp& rhs)
const
251 template <>
inline double adevs_inf() {
252 return std::numeric_limits<double>::max(); }
253 template <>
inline int adevs_inf() {
254 return std::numeric_limits<int>::max(); }
255 template <>
inline long adevs_inf() {
256 return std::numeric_limits<long>::max(); }
258 return std::numeric_limits<double>::max(); }
260 template <>
inline double adevs_zero() {
return 0.0; }
261 template <>
inline int adevs_zero() {
return 0; }
262 template <>
inline long adevs_zero() {
return 0; }
265 template <>
inline double adevs_sentinel() {
return -1.0; }
266 template <>
inline int adevs_sentinel() {
return -1; }
267 template <>
inline long adevs_sentinel() {
return -1; }
271 std::ostream& operator<<(std::ostream& strm, const adevs::Time<T>& t);