Revert "afaef"

This reverts commit 5f12afa6fd.
This commit is contained in:
Igor Timofeev
2016-11-14 17:49:00 +03:00
parent 5f12afa6fd
commit 4783fa5f8a
18 changed files with 789 additions and 377 deletions

View File

@@ -76,7 +76,11 @@ bit32.numberFromByteArray = bit32.byteArrayToNumber
-------------------------------------------------- Math extensions --------------------------------------------------
function math.round(num)
if num >= 0 then return math.floor(num + 0.5) else return math.ceil(num - 0.5) end
if num >= 0 then
return math.floor(num + 0.5)
else
return math.ceil(num - 0.5)
end
end
function math.roundToDecimalPlaces(num, decimalPlaces)
@@ -85,18 +89,31 @@ function math.roundToDecimalPlaces(num, decimalPlaces)
end
function math.getDigitCount(num)
local count = 0
while number > 0 do
number = math.floor(number / 10)
count = count + 1
end
return count
return num == 0 and 1 or math.ceil(math.log(num + 1, 10))
end
function math.doubleToString(num, digitCount)
return string.format("%." .. (digitCount or 1) .. "f", num)
end
function math.shortenNumber(number, digitCount)
local shortcuts = {
"K",
"M",
"B",
"T"
}
local index = math.floor(math.log(number, 1000))
if number < 1000 then
return number
elseif index > #shortcuts then
index = #shortcuts
end
return math.roundToDecimalPlaces(number / 1000 ^ index, digitCount) .. shortcuts[index]
end
-------------------------------------------------- Table extensions --------------------------------------------------
local function doSerialize(array, text, prettyLook, indentationSymbol, oldIndentationSymbol, equalsSymbol, currentRecusrionStack, recursionStackLimit)