From 94da4e1aa29a68cb723898a63bd01568bbbd8c4f Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 24 Feb 2014 10:20:53 +0100 Subject: [PATCH] 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. --- Source/Core/Common/MathUtil.h | 4 ++-- Source/Core/DolphinWX/GameListCtrl.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index da12822f5d..14b9309fc6 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -150,7 +150,7 @@ float MathFloatVectorSum(const std::vector&); #define ROUND_DOWN(x, a) ((x) & ~((a) - 1)) // Rounds down. 0 -> undefined -inline u64 Log2(u64 val) +inline int Log2(u64 val) { #if defined(__GNUC__) return 63 - __builtin_clzll(val); @@ -161,7 +161,7 @@ inline u64 Log2(u64 val) return result; #else - u64 result = -1; + int result = -1; while (val != 0) { val >>= 1; diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index bd420f8156..6029c741a4 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -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(_size, 1)) / 10; - auto const unit_size = (1 << (unit * 10)); + const u64 unit = Log2(std::max(_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])); }