add Scale/Min/Max/Abs non-member functions
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 01 Nov 2006 13:27:32 +0100
changeset 151 8395af452e55
parent 150 663120712cd9
child 152 f3e570a78662
add Scale/Min/Max/Abs non-member functions
src/simulator/nstime.h
src/simulator/time.cc
--- a/src/simulator/nstime.h	Wed Nov 01 13:11:30 2006 +0100
+++ b/src/simulator/nstime.h	Wed Nov 01 13:27:32 2006 +0100
@@ -57,6 +57,12 @@
   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);
--- a/src/simulator/time.cc	Wed Nov 01 13:11:30 2006 +0100
+++ b/src/simulator/time.cc	Wed Nov 01 13:27:32 2006 +0100
@@ -118,6 +118,32 @@
   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));