summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/common.h5
-rw-r--r--lib_generic/strmhz.c6
2 files changed, 7 insertions, 4 deletions
diff --git a/include/common.h b/include/common.h
index e65904413..b8a654a8a 100644
--- a/include/common.h
+++ b/include/common.h
@@ -692,8 +692,9 @@ void __attribute__((weak)) show_boot_progress (int val);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
-#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#define DIV_ROUND(n,d) (((n) + ((d)/2)) / (d))
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
#define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
diff --git a/lib_generic/strmhz.c b/lib_generic/strmhz.c
index d0b6bc60d..342cf2b21 100644
--- a/lib_generic/strmhz.c
+++ b/lib_generic/strmhz.c
@@ -27,9 +27,11 @@ char *strmhz (char *buf, long hz)
long l, n;
long m;
- n = hz / 1000000L;
+ n = DIV_ROUND(hz, 1000000L);
l = sprintf (buf, "%ld", n);
- m = (hz % 1000000L) / 1000L;
+
+ hz -= n * 1000000L;
+ m = DIV_ROUND(hz, 1000L);
if (m != 0)
sprintf (buf + l, ".%03ld", m);
return (buf);