]> granicus.if.org Git - procps-ng/commitdiff
free.c - correct conversion to decimal multiples
authorgetzze <getzze@gmail.com>
Fri, 4 Nov 2016 01:09:58 +0000 (01:09 +0000)
committerCraig Small <csmall@enc.com.au>
Sat, 13 Jan 2018 04:38:59 +0000 (15:38 +1100)
free.c

diff --git a/free.c b/free.c
index 91fa4c71d91ea319bcf2254cef50fd8668aca5fe..5807e42cbe6f75d8548f3bce88d09b53a5028269 100644 (file)
--- a/free.c
+++ b/free.c
@@ -130,17 +130,10 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
                        snprintf(buf, sizeof(buf), "%lld", ((long long int)size) * 1024);
                        return buf;
                }
-               if (args.exponent == 2) {
-                       if (!(flags & FREE_SI))
-                               snprintf(buf, sizeof(buf), "%ld", size);
-                       else
-                               snprintf(buf, sizeof(buf), "%ld", (long int)(size / 0.9765625));
-                       return buf;
-               }
-               if (args.exponent > 2) {
+               if (args.exponent > 1) {
                        /* In desired scale. */
                        snprintf(buf, sizeof(buf), "%ld",
-                                (long int)(size / power(base, args.exponent - 2))
+                                (long int)((size / 1024) * base / power(base, args.exponent - 2))
                            );
                        return buf;
                }
@@ -155,29 +148,18 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
                                return buf;
                        break;
                case 2:
-
-                       if (!(flags & FREE_SI)) {
-                               if (4 >= snprintf(buf, sizeof(buf), "%ld%c", size, *up))
-                                       return buf;
-                       } else {
-                               if (4 >=
-                                   snprintf(buf, sizeof(buf), "%ld%c",
-                                            (long)(size / 0.9765625), *up))
-                                       return buf;
-                       }
-                       break;
                case 3:
                case 4:
                case 5:
                case 6:
-                       if (4 >=
-                           snprintf(buf, sizeof(buf), "%.1f%c",
-                                    (float)(size / power(base, i - 2)), *up))
-                               return buf;
-                       if (4 >=
-                           snprintf(buf, sizeof(buf), "%ld%c",
-                                    (long)(size / power(base, i - 2)), *up))
-                               return buf;
+            if (4 >=
+                snprintf(buf, sizeof(buf), "%.1f%c",
+                     (float)((size / 1024) * base / power(base, i - 2)), *up))
+                return buf;
+            if (4 >=
+                snprintf(buf, sizeof(buf), "%ld%c",
+                     (long)((size / 1024) * base / power(base, i - 2)), *up))
+                return buf;
                        break;
                case 7:
                        break;