use round() for double
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Wed, 18 Aug 2004 23:36:25 +0000 (23:36 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Wed, 18 Aug 2004 23:36:25 +0000 (23:36 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@804 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/time.h
ltt/branches/poly/ltt/tracefile.c

index 483e2e58a5bf3a8d21fb8c9572506ad55173d36b..33feff2824f39034f540c88f90924949bb3ae5d6 100644 (file)
@@ -115,9 +115,9 @@ static inline double ltt_time_to_double(LttTime t1)
   if(t1.tv_sec > MAX_TV_SEC_TO_DOUBLE)
     g_warning("Precision loss in conversion LttTime to double");
 #endif //EXTRA_CHECK
-  return ((double)((guint64)t1.tv_sec<<DOUBLE_SHIFT)
+  return round(((double)((guint64)t1.tv_sec<<DOUBLE_SHIFT)
                   * (double)DOUBLE_SHIFT_CONST_MUL)
-                  + (double)t1.tv_nsec;
+                  + (double)t1.tv_nsec);
 }
 
 
@@ -139,7 +139,7 @@ static inline LttTime ltt_time_from_double(double t1)
   LttTime res;
   //res.tv_sec = t1/(double)NANOSECONDS_PER_SECOND;
   res.tv_sec = (guint64)(t1 * DOUBLE_SHIFT_CONST_DIV) >> DOUBLE_SHIFT;
-  res.tv_nsec = (t1 - (((guint64)res.tv_sec<<LTT_TIME_UINT_SHIFT))
+  res.tv_nsec = (round(t1) - (((guint64)res.tv_sec<<LTT_TIME_UINT_SHIFT))
                                * LTT_TIME_UINT_SHIFT_CONST);
   return res;
 }
index 4c33a21f2c8027a96e3eb4dfa6f098d311d267ef..cc953d8d8709cb1d1e41a190ffccbeaa014b4df9 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <errno.h>
 #include <unistd.h>
+#include <math.h>
 
 // For realpath
 #include <limits.h>
@@ -1199,8 +1200,9 @@ int readBlock(LttTracefile * tf, int whichBlock)
 
   getCyclePerNsec(tf);
 
-  tf->overflow_nsec = (-((double)(tf->a_block_start->cycle_count&0xFFFFFFFF))
-                                        * tf->nsec_per_cycle);
+  tf->overflow_nsec = round(
+                        (-((double)(tf->a_block_start->cycle_count&0xFFFFFFFF))
+                                        * tf->nsec_per_cycle));
 
   tf->current_event_time = getEventTime(tf);  
 
@@ -1226,8 +1228,8 @@ void updateTracefile(LttTracefile * tf)
   tf->prev_event_time.tv_nsec = 0;
   tf->count = 0;
 
-  tf->overflow_nsec = (-((double)tf->a_block_start->cycle_count)
-                                        * tf->nsec_per_cycle);
+  tf->overflow_nsec = round((-((double)tf->a_block_start->cycle_count)
+                                        * tf->nsec_per_cycle));
 
 }
 
@@ -1308,7 +1310,7 @@ void getCyclePerNsec(LttTracefile * t)
   t->nsec_per_cycle = (double)lBufTotalNSec / (double)lBufTotalCycle;
 
   /* Pre-multiply one overflow (2^32 cycles) by nsec_per_cycle */
-  t->one_overflow_nsec = t->nsec_per_cycle * (double)0x100000000ULL;
+  t->one_overflow_nsec = round(t->nsec_per_cycle * (double)0x100000000ULL);
 
 }
 
@@ -1348,9 +1350,9 @@ static inline LttTime getEventTime(LttTracefile * tf)
   if(unlikely(evId == TRACE_BLOCK_START)) {
      lEventNSec = 0;
   } else if(unlikely(evId == TRACE_BLOCK_END)) {
-    lEventNSec = ((double)
+    lEventNSec = round(((double)
                  (tf->a_block_end->cycle_count - tf->a_block_start->cycle_count)
-                           * tf->nsec_per_cycle);
+                           * tf->nsec_per_cycle));
   }
 #if 0
   /* If you want to make heart beat a special case and use their own 64 bits
@@ -1365,7 +1367,7 @@ static inline LttTime getEventTime(LttTracefile * tf)
   }
 #endif //0
   else {
-    lEventNSec = (gint64)((double)cycle_count * tf->nsec_per_cycle)
+    lEventNSec = (gint64)round(((double)cycle_count * tf->nsec_per_cycle))
                                 +tf->overflow_nsec;
   }
 
This page took 0.025772 seconds and 4 git commands to generate.