]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
trspeed: use long double for transfer speed calculation
authorDaniel Stenberg <daniel@haxx.se>
Sat, 8 May 2021 11:10:06 +0000 (13:10 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 9 May 2021 13:59:44 +0000 (15:59 +0200)
lib/progress.c

index 31808aa8c66276faf4c7e76f735e6451f0584b42..dffaa074e4d216b61c066d2d72c96c9c40dfbf23 100644 (file)
@@ -369,26 +369,13 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
   }
 }
 
-/* returns the average speed */
-static curl_off_t trspeed(curl_off_t size, curl_off_t us)
+/* returns the average speed in bytes / second */
+static curl_off_t trspeed(curl_off_t size, /* number of bytes */
+                          curl_off_t us)   /* microseconds */
 {
-  curl_off_t sec;
-  if(size < CURL_OFF_T_MAX/1000000) {
-    if(us < 1)
-      return size * 1000000;
-    return (size * 1000000) / us;
-  }
-  else if(size < CURL_OFF_T_MAX/1000) {
-    curl_off_t ms = us/1000;
-    if(ms < 1)
-      return size * 1000;
-    return (size * 1000) / ms;
-  }
-  sec = us / 1000000;
-  if(sec < 1)
-    return size;
-
-  return size / sec;
+  if(us < 1)
+    return size * 1000000;
+  return (curl_off_t)((long double)size/us * 1000000);
 }
 
 /* returns TRUE if it's time to show the progress meter */