logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

humanize.h (564B)


  1. // utils-std: Collection of commonly available Unix tools
  2. // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #include <stdbool.h> // bool
  5. #include <stddef.h> // size_t
  6. struct si_scale
  7. {
  8. double number;
  9. const char *prefix;
  10. unsigned exponent;
  11. };
  12. // dtosi(num, iec) => num ≈ number*scale^exponent where scale == iec ? 1024 : 1000
  13. // SI scale returns prefix values like k, M, G, …
  14. // IEC scale returns prefix values like KiB, MiB, GiB, …
  15. struct si_scale dtosi(double num, bool iec);