MathUtil: Change Log2 return value to int

Log2(u64) can't be bigger than 63, so there is no need in forcing a 64 bit value.
So just using a common int seems more natural.
This commit is contained in:
degasus
2014-02-24 10:20:53 +01:00
parent f99c8a0b70
commit 94da4e1aa2
2 changed files with 6 additions and 6 deletions

View File

@ -413,12 +413,12 @@ wxString NiceSizeFormat(u64 _size)
{
const char* const unit_symbols[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"};
auto const unit = Log2(std::max<u64>(_size, 1)) / 10;
auto const unit_size = (1 << (unit * 10));
const u64 unit = Log2(std::max<u64>(_size, 1)) / 10;
const u64 unit_size = (1 << (unit * 10));
// ugly rounding integer math
auto const value = (_size + unit_size / 2) / unit_size;
auto const frac = (_size % unit_size * 10 + unit_size / 2) / unit_size % 10;
const u64 value = (_size + unit_size / 2) / unit_size;
const u64 frac = (_size % unit_size * 10 + unit_size / 2) / unit_size % 10;
return StrToWxStr(StringFromFormat("%" PRIu64 ".%" PRIu64 " %s", value, frac, unit_symbols[unit]));
}