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);
static adevs::Time< T > Inf()
Value for infinity.
Definition: adevs_time.h:58
const Time & operator=(T t2)
Definition: adevs_time.h:76
Time(const Time &t2)
Copy constructor.
Definition: adevs_time.h:62
const Time & operator=(const Time &t2)
Assignment operator.
Definition: adevs_time.h:64
bool operator==(const Time &t2) const
Equivalence.
Definition: adevs_time.h:100
Definition: adevs_time.h:190
Definition: adevs_time.h:53
Time operator+(const Time &t2) const
Advance operator (this is not commutative or associative!)
Definition: adevs_time.h:83
T operator-(T t2) const
Subtract a real number (used to get the elapsed time)
Definition: adevs_time.h:95
bool operator<(T t2) const
Comparing with a T compares the real field.
Definition: adevs_time.h:71
bool operator<(const Time &t2) const
Order by t then by c.
Definition: adevs_time.h:110
static double epsilon
Definition: adevs_time.h:200
const Time & operator+=(const Time &t2)
Advance and assign.
Definition: adevs_time.h:89
int fcmp(double x1, double x2, double epsilon)
Definition: adevs_time.h:141
bool operator!=(const Time &t2) const
Not equal.
Definition: adevs_time.h:105
Time(T t=adevs_zero< T >(), unsigned int c=0)
Constructor. Default time is (0,0).
Definition: adevs_time.h:60