use realpath to get the absolute pathname, fixes some forgotten cases, especially...
[lttv.git] / ltt / branches / poly / include / ltt / time.h
index 4f8094330647ec3927c5040a8579a56cb0e23922..2cce27608baaf2aaecf5969cdb72efdb6caf7482 100644 (file)
@@ -1,3 +1,21 @@
+/* This file is part of the Linux Trace Toolkit trace reading library
+ * Copyright (C) 2003-2004 Michel Dagenais
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License Version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
 #ifndef LTT_TIME_H
 #define LTT_TIME_H
 
@@ -43,13 +61,22 @@ static inline LttTime ltt_time_add(LttTime t1, LttTime t2)
 
 static inline LttTime ltt_time_mul(LttTime t1, float f)
 {
-  double nsec;
   LttTime res;
+  float d;
+  double sec;
 
-  nsec = (double)t1.tv_nsec * f;
-  res.tv_sec = nsec / NANOSECONDS_PER_SECOND;
-  res.tv_nsec = nsec - res.tv_sec * NANOSECONDS_PER_SECOND;
-  res.tv_sec += t1.tv_sec * f;
+  if(f == 0.0){
+    res.tv_sec = 0;
+    res.tv_nsec = 0;
+  }else{
+    d = 1.0/f;
+    sec = t1.tv_sec / (double)d;
+    res.tv_sec = sec;
+    res.tv_nsec = t1.tv_nsec / (double)d + (sec - res.tv_sec) *
+                  NANOSECONDS_PER_SECOND;
+    res.tv_sec += res.tv_nsec / NANOSECONDS_PER_SECOND;
+    res.tv_nsec %= NANOSECONDS_PER_SECOND;
+  }
   return res;
 }
 
@@ -63,6 +90,8 @@ static inline LttTime ltt_time_div(LttTime t1, float f)
   res.tv_sec = sec;
   res.tv_nsec = t1.tv_nsec / (double)f + (sec - res.tv_sec) *
       NANOSECONDS_PER_SECOND;
+  res.tv_sec += res.tv_nsec / NANOSECONDS_PER_SECOND;
+  res.tv_nsec %= NANOSECONDS_PER_SECOND;
   return res;
 }
 
This page took 0.023762 seconds and 4 git commands to generate.