all repos — slstatus @ 68a3902dc533a66c1377409b34904f730ae4a7ef

my build of slstatus (tools.suckless.org/slstatus/)

Increase precision in netspeeds.c

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.
Laslo Hunhold dev@frign.de
Sat, 19 May 2018 20:09:38 +0200
commit

68a3902dc533a66c1377409b34904f730ae4a7ef

parent

422cadfd5ffd78ae1b8fdf15734e03bd0333b26e

1 files changed, 8 insertions(+), 8 deletions(-)

jump to
M components/netspeeds.ccomponents/netspeeds.c

@@ -26,8 +26,8 @@ if (pscanf(path, "%llu", &rxbytes) != 1) {

return NULL; } - return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) / - interval * 1000) : NULL; + return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) * + 1000 / interval) : NULL; } const char *

@@ -49,8 +49,8 @@ if (pscanf(path, "%llu", &txbytes) != 1) {

return 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>

@@ -88,8 +88,8 @@ warn("reading 'if_data' failed");

return NULL; } - return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) / - interval * 1000) : NULL; + return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) * + 1000 / interval) : NULL; } const char *

@@ -121,7 +121,7 @@ warn("reading 'if_data' failed");

return NULL; } - return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) / - interval * 1000) : NULL; + return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) * + 1000 / interval) : NULL; } #endif