Commit 25f86909 authored by osdl.net!shemminger's avatar osdl.net!shemminger

Auto merged

2004/08/24 11:54:13-07:00 osdl.net!shemminger
Fix calculation of percent to u32 scaling.

(Logical change 1.72)
parent c76f457e
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment