First dividing by interval before multiplying with 1000 decreases the
precision by +-(interval - 1) * 1000, as interval arithmetic always
applies the Gauß-function to the result.
This is not necessary and simply reordering the operations mitigates
this.
- return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) /
- interval * 1000) : NULL;
+ return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) *
+ 1000 / interval) : NULL;
- return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) /
- interval * 1000) : NULL;
+ return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) *
+ 1000 / interval) : NULL;
}
#elif defined(__OpenBSD__)
#include <string.h>
}
#elif defined(__OpenBSD__)
#include <string.h>
- return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) /
- interval * 1000) : NULL;
+ return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) *
+ 1000 / interval) : NULL;
- return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) /
- interval * 1000) : NULL;
+ return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) *
+ 1000 / interval) : NULL;