]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
Auto merged
authorosdl.net!shemminger <osdl.net!shemminger>
Tue, 24 Aug 2004 18:54:49 +0000 (18:54 +0000)
committerosdl.net!shemminger <osdl.net!shemminger>
Tue, 24 Aug 2004 18:54:49 +0000 (18:54 +0000)
2004/08/24 11:54:13-07:00 osdl.net!shemminger
Fix calculation of percent to u32 scaling.

(Logical change 1.72)

tc/tc_util.c

index ad72b63eadc5bf07b679ca7e424895ffb4d9d850..5545478f11d47a73809e273446884c7e88eddcd6 100644 (file)
@@ -331,25 +331,25 @@ char * sprint_size(__u32 size, char *buf)
        return buf;
 }
 
-static double percent_scale = (double)(1ull << 32) / 100.;
+static const double max_percent_value = 0xffffffff;
 
 int get_percent(__u32 *percent, const char *str)
 {
        char *p;
-       double per = strtod(str, &p);
+       double per = strtod(str, &p) / 100.;
 
-       if (per > 100.)
+       if (per > 1. || per < 0)
                return -1;
        if (*p && strcmp(p, "%"))
                return -1;
 
-       *percent = per * percent_scale;
+       *percent = (unsigned) rint(per * max_percent_value);
        return 0;
 }
 
 void print_percent(char *buf, int len, __u32 per)
 {
-       snprintf(buf, len, "%g%%", (double) per / percent_scale);
+       snprintf(buf, len, "%g%%", 100. * (double) per / max_percent_value);
 }
 
 char * sprint_percent(__u32 per, char *buf)