MCPcopy Create free account
hub / github.com/baidu/tera / FormatMeasure

Function FormatMeasure

src/common/base/string_number.cc:797–810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

795} // anonymous namespace
796
797std::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
812std::string FormatBinaryMeasure(int64_t n, const char* unit) {
813 // see

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68