| 795 | } // anonymous namespace |
| 796 | |
| 797 | std::string FormatMeasure(double n, const char* unit) { |
| 798 | // see |
| 799 | // http://zh.wikipedia.org/wiki/%E5%9B%BD%E9%99%85%E5%8D%95%E4%BD%8D%E5%88%B6%E8%AF%8D%E5%A4%B4 |
| 800 | static const char* const base_prefixes[] = { |
| 801 | "y", "z", "a", "f", "p", "n", "u", "m", // negative exponential |
| 802 | "", "k", "M", "G", "T", "P", "E", "Z", "Y"}; |
| 803 | static const int negative_prefixes_size = 8; |
| 804 | static const int prefixes_size = ARRAY_SIZE(base_prefixes); |
| 805 | |
| 806 | const char* const* prefixes = base_prefixes + negative_prefixes_size; |
| 807 | |
| 808 | return NumberToHumanReadableString<double, 1000>(n, prefixes, unit, -negative_prefixes_size, |
| 809 | prefixes_size - negative_prefixes_size - 1); |
| 810 | } |
| 811 | |
| 812 | std::string FormatBinaryMeasure(int64_t n, const char* unit) { |
| 813 | // see |