mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:37:35 +00:00
AK: Implement terabytes, petabytes, exabytes
This commit is contained in:
parent
7ffc6c371a
commit
607fac662d
3 changed files with 20 additions and 12 deletions
|
@ -31,13 +31,13 @@
|
|||
namespace AK {
|
||||
|
||||
// FIXME: Remove this hackery once printf() supports floats.
|
||||
static String number_string_with_one_decimal(u64 number, u32 unit, const char* suffix)
|
||||
static String number_string_with_one_decimal(u64 number, u64 unit, const char* suffix)
|
||||
{
|
||||
int decimal = (number % unit) * 10 / unit;
|
||||
return String::formatted("{}.{} {}", number / unit, decimal, suffix);
|
||||
}
|
||||
|
||||
static inline String human_readable_size(size_t size)
|
||||
static inline String human_readable_size(u64 size)
|
||||
{
|
||||
if (size < 1 * KiB)
|
||||
return String::formatted("{} B", size);
|
||||
|
@ -45,7 +45,13 @@ static inline String human_readable_size(size_t size)
|
|||
return number_string_with_one_decimal(size, KiB, "KiB");
|
||||
if (size < 1 * GiB)
|
||||
return number_string_with_one_decimal(size, MiB, "MiB");
|
||||
return number_string_with_one_decimal(size, GiB, "GiB");
|
||||
if (size < 1 * TiB)
|
||||
return number_string_with_one_decimal(size, GiB, "GiB");
|
||||
if (size < 1 * PiB)
|
||||
return number_string_with_one_decimal(size, TiB, "TiB");
|
||||
if (size < 1 * EiB)
|
||||
return number_string_with_one_decimal(size, PiB, "PiB");
|
||||
return number_string_with_one_decimal(size, EiB, "EiB");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue