| 446 | |
| 447 | |
| 448 | string 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 | |
| 470 | string getTableTitleStr(string title) { |
no test coverage detected