+/* 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
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;
}
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;
}