C++ / build (pull_request) Failing after 15s
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 28s
Python / lint-format (pull_request) Successful in 45s
Python / test (pull_request) Successful in 38s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m45s
34 lines
706 B
C++
34 lines
706 B
C++
#include "usagefmt.hpp"
|
|
|
|
namespace {
|
|
|
|
constexpr qreal kKib = 1024.0;
|
|
constexpr qreal kMib = kKib * 1024.0;
|
|
constexpr qreal kGib = kMib * 1024.0;
|
|
|
|
bool finitePositive(qreal v) {
|
|
return std::isfinite(v) && v >= 0.0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace ZShell::services::usagefmt {
|
|
|
|
FormatResult UsageFmt::formatKib(qreal kib, qreal total) const {
|
|
if (!finitePositive(kib) || !finitePositive(total)) {
|
|
return {0.0, 0.0, "KiB"};
|
|
}
|
|
if (total >= kGib) {
|
|
return {kib / kGib, total / kGib, "TiB"};
|
|
}
|
|
if (total >= kMib) {
|
|
return {kib / kMib, total / kMib, "GiB"};
|
|
}
|
|
if (total >= kKib) {
|
|
return {kib / kKib, total / kKib, "MiB"};
|
|
}
|
|
return {kib, total, "KiB"};
|
|
}
|
|
|
|
} // namespace ZShell::services::usagefmt
|