add Scale/Min/Max/Abs non-member functions

This commit is contained in:
Mathieu Lacage
2006-11-01 13:27:32 +01:00
parent 0fade9d7af
commit aa2ba3ea27
2 changed files with 32 additions and 0 deletions

View File

@@ -57,6 +57,12 @@ class Time {
int64_t m_ns;
};
Time Scale (Time const &time, double scale);
Time Abs (Time const &time);
Time Max (Time const &a, Time const &b);
Time Min (Time const &a, Time const &b);
Time operator + (Time const &lhs, Time const &rhs);
Time operator - (Time const &lhs, Time const &rhs);
bool operator == (Time const &lhs, Time const &rhs);

View File

@@ -118,6 +118,32 @@ GetNs (Time const &time)
return time.ApproximateToNanoSeconds ();
}
Time Scale (Time const &time, double scale)
{
return NanoSeconds ((int64_t) (GetNs (time) * scale));
}
Time Abs (Time const &time)
{
int64_t retval = GetNs (time);
retval = (retval<0)?(-retval):(retval);
return NanoSeconds (retval);
}
Time Max (Time const &ta, Time const &tb)
{
int64_t a = GetNs (ta);
int64_t b = GetNs (tb);
int64_t retval = (a>b)?(a):(b);
return NanoSeconds (retval);
}
Time Min (Time const &ta, Time const &tb)
{
int64_t a = GetNs (ta);
int64_t b = GetNs (tb);
int64_t retval = (a<b)?(a):(b);
return NanoSeconds (retval);
}
Time operator + (Time const &lhs, Time const &rhs)
{
return NanoSeconds (GetNs (lhs) + GetNs (rhs));