2 #ifndef ENIGMA_SIZE_UTILS_H
3 #define ENIGMA_SIZE_UTILS_H
19 static std::string
FriendlySize(
const std::size_t bytes) noexcept {
20 constexpr
const std::size_t KB = 1024;
23 return std::to_string(bytes) +
" Bytes";
25 constexpr
const char *sizes[]{
"Bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB"};
26 const std::size_t i =
static_cast<std::size_t
>(std::floor(
static_cast<double>(std::log(bytes) / std::log(KB))));
28 std::ostringstream oss{};
30 << std::setprecision(2)
31 <<
static_cast<float>(bytes / std::pow(KB, i))
40 #define ENIGMA_BYTES_TO_KB(bytes) (static_cast<float>(bytes) / 1024.0f)
41 #define ENIGMA_BYTES_TO_MB(bytes) (static_cast<float>(bytes) / 1024.0f / 1024.0f)
42 #define ENIGMA_BYTES_TO_GB(bytes) (static_cast<float>(bytes) / 1024.0f / 1024.0f / 1024.0f)
43 #define ENIGMA_BYTES_TO_TB(bytes) (static_cast<float>(bytes) / 1024.0f / 1024.0f / 1024.0f / 1024.0f)
46 #define ENIGMA_MB_TO_BYTES(mb) (static_cast<std::size_t>(mb) * 1024 * 1024)
47 #define ENIGMA_MB_TO_KB(mb) (static_cast<std::size_t>(mb) * 1024)
48 #define ENIGMA_MB_TO_GB(mb) (static_cast<float>(mb) / 1024.0f)
49 #define ENIGMA_MB_TO_TB(mb) (static_cast<float>(mb) / 1024.0f / 1024.0f)
51 #define ENIGMA_KB_TO_BYTES(kb) (static_cast<std::size_t>(kb) * 1024)
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
static std::string FriendlySize(const std::size_t bytes) noexcept