MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / printer_getMemoryWithUnitStr

Function printer_getMemoryWithUnitStr

quest/src/core/printer.cpp:448–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446
447
448string printer_getMemoryWithUnitStr(size_t numBytes) {
449
450 // retain "bytes" instead of "B" since more recognisable
451 vector<string> units = {"bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"};
452
453 // unit sizes (in bytes) may overflow; but then so too will numBytes
454 vector<size_t> sizes(units.size());
455 for (size_t i=0; i<units.size(); i++)
456 sizes[i] = powerOf2(10 * i); // = 1024^i
457
458 // find the biggest unit for which numBytes/sizes[ind] > 1
459 int ind = 1;
460 while (numBytes > sizes[ind])
461 ind++;
462 ind--;
463
464 // express numBytes in terms of new unit, forcefully rounding to 4 sig-figs max
465 qreal frac = numBytes / static_cast<qreal>(sizes[ind]);
466 return floatToStr(frac, false, 4) + " " + units[ind];
467}
468
469
470string getTableTitleStr(string title) {

Callers 5

getMemoryCostsStrFunction · 0.85
printPrecisionInfoFunction · 0.85
printCpuInfoFunction · 0.85
printGpuInfoFunction · 0.85
printMemoryInfoFunction · 0.85

Calls 2

powerOf2Function · 0.85
floatToStrFunction · 0.85

Tested by

no test coverage detected