#include "compat.h"
#include "calc.h"

double mrtg_calcspeed(uint64_t counter_imp1, uint64_t counter_imp2, double elapse_imp, uint64_t counter_avg1, uint64_t counter_avg2, double elapse_avg) {
	double impulserate;
	double datarate;
	int wraps=0;

	if (elapse_imp>0.00) {
		if (counter_imp2<counter_imp1) counter_imp2+=4294967296;
		impulserate=(counter_imp2-counter_imp1)/elapse_imp;
		wraps=((impulserate*elapse_avg)/4294967296); /* Note that `wraps' is an integer. */
		counter_avg2+=(4294967296*wraps);
	}
	datarate=(counter_avg2-counter_avg1)/elapse_avg;

	return(datarate);
}
