What happens when memdiff and/or totaldiff are negative? I was hoping for a negative memperc, but it doesn't seem like that's happening. Messing around in Python gives all sorts of confusing results when I plug in negative numbers.
local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
if mem then
if totaldiff == 0 then totaldiff = 0.001 end
memperc = (memdiff / totaldiff * 100)
local num = memperc
if num < 1 then num = 1 end
if num > 100 then num = 100 end
local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
return GetColorCode(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b)
end
Edit: Oh come on, the question isn't a bad question. Maybe I should have been more clear on what I'm trying to do.
I'm taking two memory values, one overall and one specific to this addon. I'm creating a difference by doing thismem - lastmem
. That's my difference. I have two of them, overall and addon specific. When Lua garbage collects, I get over 100% when I do memdiff / totaldiff * 100
, when it should be negative. I don't know why.
Edit2:
Let me give some examples.
lastmem = 95
mem = 100.
lastaddonmem = 20
addonmem = 25.
totaldiff = mem - lastmem
addondiff = addonmem - lastaddonmem
perc = addondiff / totaldiff * 100
perc = 100
lastmem = 100
mem = 95.
lastaddonmem = 25
addonmem = 20.
totaldiff = mem - lastmem
addondiff = addonmem - lastaddonmem
perc = addondiff / totaldiff * 100
perc = 100
I know I'm going about this the wrong way. That's why I'm here.
Edit3: Why do you guys want to close this? I admit I'm dumb when it comes to math. Is it that people have that much intolerance for the mathematically challenged? I simply don't get math. Numbers confuse me like no other challenge of mine. I'm not uneducated. I have a learning disability. I don't see what the big deal is.
I ended up going with:
local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
if mem then
if totaldiff == 0 then totaldiff = 0.0001 end
local memperc
if memdiff < 0 then
memdiff = abs(memdiff)
totaldiff = abs(totaldiff)
memperc = memdiff / totaldiff * 100
memperc = memperc * -1
else
memperc = memdiff / totaldiff * 100
end
local num = floor(memperc)
if num < 1 then num = 1 end
if num > 100 then num = 100 end
local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3]
return GetColorCode(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b)
end