Increase precision in netspeeds.c
authorLaslo Hunhold <dev@frign.de>
Sat, 19 May 2018 18:09:38 +0000 (20:09 +0200)
committerAaron Marcher <me@drkhsh.at>
Sat, 19 May 2018 18:14:09 +0000 (20:14 +0200)
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.

components/netspeeds.c

index 6adc3ea804fc5ed388bcb8bd38a776ffdc127d62..32e78d6409092961487c808bbbf21c13669d202d 100644 (file)
@@ -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 *
@@ -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>
@@ -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 *
                        return NULL;
                }
 
-               return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) /
-                                              interval * 1000) : NULL;
+               return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) *
+                                              1000 / interval) : NULL;
        }
 #endif