MCPcopy Create free account
hub / github.com/apache/impala / ToStringWithoutRounding

Method ToStringWithoutRounding

be/src/gutil/strings/human_readable.cc:141–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141string HumanReadableNumBytes::ToStringWithoutRounding(int64 num_bytes) {
142 if (num_bytes == kint64min) {
143 // Special case for number with not representable nagation.
144 return "-8E";
145 }
146
147 const char *neg_str = GetNegStr(&num_bytes);
148 static const char units[] = "BKMGTPE"; // int64 only goes up to E.
149
150 int64 num_units = num_bytes;
151 int unit_type = 0;
152 for (; unit_type < arraysize(units); unit_type++) {
153 if (num_units % 1024 != 0) {
154 // Not divisible by the next unit.
155 break;
156 }
157
158 int64 next_units = num_units >> 10;
159 if (next_units == 0) {
160 // Less than the next unit.
161 break;
162 }
163
164 num_units = next_units;
165 }
166 return StringPrintf("%s%" PRId64 "%c", neg_str, num_units, units[unit_type]);
167}
168
169string HumanReadableInt::ToString(int64 value) {
170 string s;

Callers

nothing calls this directly

Calls 2

GetNegStrFunction · 0.85
StringPrintfFunction · 0.85

Tested by

no test coverage detected