summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-05-08 13:10:06 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-05-09 15:59:44 +0200
commit8a75224a6986a5742215e0e73e1ac0d3419eff43 (patch)
treebd4a6627d93e0774196080a82494d2736fd09a51 /lib
parent7ab54e8f413cb8fff8e9dca805e22c83fd632885 (diff)
downloadcurl-8a75224a6986a5742215e0e73e1ac0d3419eff43.tar.gz
trspeed: use long double for transfer speed calculation
Diffstat (limited to 'lib')
-rw-r--r--lib/progress.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/lib/progress.c b/lib/progress.c
index 31808aa8c..dffaa074e 100644
--- a/lib/progress.c
+++ b/lib/progress.c
@@ -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 */