开发者

Back with another math question [closed]

开发者 https://www.devze.com 2023-01-15 21:22 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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 e开发者_高级运维nd
    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


if totaldiff == 0 then totaldiff = 0.001 end 

    memperc = (memdiff / totaldiff * 100)

So if memdiff > 0.001 memperc will be greater than 100

EG 1: (0.001/0.001)*100 = 100

EG 2: (0.002/0.001)*100 = 200


  • if memdiff and totaldiff have the same sign, then memdiff/totaldiff > 0. Multiplying by 100 doesn't change the sign

  • if memdiff and totaldiff have different signs, then memdiff/totaldiff < 0. Multiplying by 100, again, doesn't change this.

  • if memdiff == 0 then memdiff/totaldiff == 0. Multiplying by 100 doesn't change this.

to figure out why memdiff/totaldiff * 100 > 1, just note that this implies that memdiff*100 > totaldiff which implies that 100 > totaldiff/memdiff. There's no rules that say that percentages have to be between 0 and 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消