num2str(): Add the E (exa) prefix
authorBart Van Assche <bvanassche@acm.org>
Thu, 2 Jul 2020 23:31:35 +0000 (16:31 -0700)
committerBart Van Assche <bvanassche@acm.org>
Thu, 2 Jul 2020 23:31:57 +0000 (16:31 -0700)
This change guarantees that all 64-bit integers that should be assigned a
multiplier are assigned a multiplier.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
lib/num2str.c
unittests/lib/num2str.c

index 7f628d29a05121167f147de03700524e67205c31..726f1c44159fd8a16379777411030b262eeb6cb1 100644 (file)
@@ -20,8 +20,8 @@
  */
 char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units)
 {
-       const char *sistr[] = { "", "k", "M", "G", "T", "P" };
-       const char *iecstr[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
+       const char *sistr[] = { "", "k", "M", "G", "T", "P", "E" };
+       const char *iecstr[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei" };
        const char **unitprefix;
        static const char *const unitstr[] = {
                [N2S_NONE]      = "",
index 931e28a4d4805290d590527a659a628aed54c31b..a3492a8d925aa0d24b4e8f33f9402a36777165d0 100644 (file)
@@ -19,8 +19,8 @@ static const struct testcase testcases[] = {
        { UINT64_MAX, 99, 1, 0, N2S_NONE, "18446744073709551615" },
        { 18446744073709551, 2, 1, 0, N2S_NONE, "18P" },
        { 18446744073709551, 4, 1, 0, N2S_NONE, "18.4P" },
-       { UINT64_MAX, 2, 1, 0, N2S_NONE, "18" },
-       { UINT64_MAX, 4, 1, 0, N2S_NONE, "18.4" },
+       { UINT64_MAX, 2, 1, 0, N2S_NONE, "18E" },
+       { UINT64_MAX, 4, 1, 0, N2S_NONE, "18.4E" },
 };
 
 static void test_num2str(void)