diff options
author | osdl.net!shemminger <osdl.net!shemminger> | 2004-10-19 19:51:41 +0000 |
---|---|---|
committer | osdl.net!shemminger <osdl.net!shemminger> | 2004-10-19 19:51:41 +0000 |
commit | abf1d0b09798a2c0b290be551a903f927efa4540 (patch) | |
tree | a2658b062244162dcfacf6db696ebfa55794db49 /tc | |
parent | d7b93e1e37d1f45624b343a809ef03ca8dbcd1bb (diff) |
fix scaling in print_rates (for bits).
(Logical change 1.95)
Diffstat (limited to 'tc')
-rw-r--r-- | tc/tc_util.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/tc/tc_util.c b/tc/tc_util.c index 5cc9e38a..20843de6 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -183,22 +183,19 @@ void print_rate(char *buf, int len, __u32 rate) extern int use_iec; if (use_iec) { - if (tmp >= 1024*1023 && - fabs(1024*1024*rint(tmp/(1024*1024)) - tmp) < 1024) - snprintf(buf, len, "%gMibit", rint(tmp/(1024*1024))); - else if (tmp >= 1024-16 && fabs(1024*rint(tmp/1024) - tmp) < 16) - snprintf(buf, len, "%gKibit", rint(tmp/1024)); + if (tmp >= 1000.0*1024.0*1024.0) + snprintf(buf, len, "%.0fMibit", tmp/1024.0*1024.0); + else if (tmp >= 1000.0*1024) + snprintf(buf, len, "%.0fKibit", tmp/1024); else - snprintf(buf, len, "%ubit", rate); - - } else { - if (tmp >= 999999 && - fabs(1000000.*rint(tmp/1000000.) - tmp) < 1000) - snprintf(buf, len, "%gMbit", rint(tmp/1000000.)); - else if (tmp >= 990 && fabs(1000.*rint(tmp/1000.) - tmp) < 10) - snprintf(buf, len, "%gKbit", rint(tmp/1000.)); + snprintf(buf, len, "%.0fbit", tmp); + } else { + if (tmp >= 1000.0*1000000.0) + snprintf(buf, len, "%.0fMbit", tmp/1000000.0); + else if (tmp >= 1000.0 * 1000.0) + snprintf(buf, len, "%.0fKbit", tmp/1000.0); else - snprintf(buf, len, "%ubit", rate); + snprintf(buf, len, "%.0fbit", tmp); } } |