[hackers] [slstatus] Increase precision in netspeeds.c || Laslo Hunhold
commit 68a3902dc533a66c1377409b34904f730ae4a7ef
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Sat May 19 20:09:38 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Sat May 19 20:14:09 2018 +0200
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.
diff --git a/components/netspeeds.c b/components/netspeeds.c
index 6adc3ea..32e78d6 100644
--- a/components/netspeeds.c
+++ b/components/netspeeds.c
_AT_@ -26,8 +26,8 @@
return NULL;
}
- return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) /
- interval * 1000) : NULL;
+ return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) *
+ 1000 / interval) : NULL;
}
const char *
_AT_@ -49,8 +49,8 @@
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>
_AT_@ -88,8 +88,8 @@
return NULL;
}
- return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) /
- interval * 1000) : NULL;
+ return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) *
+ 1000 / interval) : NULL;
}
const char *
_AT_@ -121,7 +121,7 @@
return NULL;
}
- return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) /
- interval * 1000) : NULL;
+ return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) *
+ 1000 / interval) : NULL;
}
#endif
Received on Sat May 19 2018 - 20:21:20 CEST
This archive was generated by hypermail 2.3.0
: Sat May 19 2018 - 20:24:24 CEST