| 870 | |
| 871 | template <typename T, int Base> |
| 872 | std::string NumberToHumanReadableString( |
| 873 | T number, |
| 874 | const char* const*prefixes, |
| 875 | const char* unit, |
| 876 | int min_shift, |
| 877 | int max_shift |
| 878 | ) |
| 879 | { |
| 880 | bool neg = number < 0; |
| 881 | double n = fabs(static_cast<double>(number)); |
| 882 | |
| 883 | int shift; |
| 884 | GetMantissaAndShift<Base>(n, min_shift, max_shift, &n, &shift); |
| 885 | |
| 886 | const char* sep = ""; |
| 887 | if (unit[0] == ' ') |
| 888 | { |
| 889 | ++unit; |
| 890 | // ignore unit if it is " " and prefix is unnecessary |
| 891 | if (shift != 0 || unit[0] != '\0') |
| 892 | sep = " "; |
| 893 | } |
| 894 | |
| 895 | char buffer[16]; |
| 896 | int length = sprintf(buffer, "%s%.*g%s%s", // NOLINT(runtime/printf) |
| 897 | neg ? "-": "", n < 1000 ? 3 : 4, n, sep, |
| 898 | prefixes[shift]); |
| 899 | std::string result(buffer, length); |
| 900 | result += unit; |
| 901 | return result; |
| 902 | } |
| 903 | |
| 904 | } // namespace |
| 905 |
nothing calls this directly
no outgoing calls
no test coverage detected