From 8e5ff7d47d3fbe3b6bf536dad7454ddf0bcc6266 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 9 Jun 2006 18:38:58 +0000 Subject: [PATCH] better rounding function for sigar_mem_calc_ram --- src/sigar_util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sigar_util.c b/src/sigar_util.c index 38412fdb..8899e85e 100644 --- a/src/sigar_util.c +++ b/src/sigar_util.c @@ -312,12 +312,12 @@ int sigar_proc_count(sigar_t *sigar, sigar_uint64_t *total) int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem) { - sigar_uint64_t lram = (mem->total / (1024 * 1024)); - int ram = (int)lram; /* must cast after division */ - int remainder = ram % 8; + sigar_uint64_t total = (mem->total / (1024 * 1024)); + int size = (int)total; /* must cast after division */ + int ram; - if (remainder > 0) { - ram += (8 - remainder); + for (ram=1; size; size >>= 1) { + ram <<= 1; } mem->ram = ram;