/**
* compute fraction of given struct timeval
*
- * \param div the integer value to divide by
+ * \param divisor the integer value to divide by
* \param tv the timevalue to divide
* \param result holds (1 / mult) * tv upon return
*/
-void tv_divide(const unsigned long div, const struct timeval *tv,
+void tv_divide(const unsigned long divisor, const struct timeval *tv,
struct timeval *result)
{
- long unsigned q = tv->tv_usec / div;
- result->tv_sec = tv->tv_sec / div;
- result->tv_usec = (tv->tv_sec - result->tv_sec * div) * 1000 * 1000 / div;
+ long unsigned q;
+
+ if (!divisor) {
+ PARA_EMERG_LOG("%s\n", "division by zero");
+ exit(EXIT_FAILURE);
+ }
+ q = tv->tv_usec / divisor;
+ result->tv_sec = tv->tv_sec / divisor;
+ result->tv_usec = (tv->tv_sec - result->tv_sec * divisor)
+ * 1000 * 1000 / divisor;
if (result->tv_usec + q >= 1000 * 1000) {
result->tv_sec++;
result->tv_usec = 1000 * 1000 - result->tv_usec - q;
{
struct timeval tmp1, tmp2, tmp3;
int ret = 1, subtract = ((a > 0 && b < 0) || (a < 0 && b > 0));
- unsigned long a1 = ABS(a), b1 = ABS(b);
+ unsigned long a1 = PARA_ABS(a), b1 = PARA_ABS(b);
tv_scale(a1, tv1, &tmp1);
tv_scale(b1, tv2, &tmp2);