When displaying sizes as a floating-point number (e.g. "123.4 Mb"),
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 17 Nov 2010 21:25:17 +0000 (21:25 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 17 Nov 2010 21:25:17 +0000 (21:25 +0000)
don't compute that number in integer arithmetic and then cast it to
double!

git-svn-id: svn://svn.tartarus.org/sgt/agedu@9025 cda61777-01e9-0310-a592-d414129be87e

html.c

diff --git a/html.c b/html.c
index e72d1bd..d316d1e 100644 (file)
--- a/html.c
+++ b/html.c
@@ -325,12 +325,17 @@ static void compute_display_size(unsigned long long size,
        "%#.1f Pb", "%#.1f Eb", "%#.1f Zb", "%#.1f Yb"
     };
     int shift = 0;
-
-    while (size >= 1024 && shift < lenof(fmts)-1) {
-       size >>= 10;
+    unsigned long long tmpsize;
+    double denominator;
+
+    tmpsize = size;
+    denominator = 1.0;
+    while (tmpsize >= 1024 && shift < lenof(fmts)-1) {
+       tmpsize >>= 10;
+        denominator *= 1024.0;
        shift++;
     }
-    *display_size = (double)size;
+    *display_size = size / denominator;
     *fmt = fmts[shift];
 }