Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1067143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:07:05+00:00 2026-05-16T20:07:05+00:00

What happens when memdiff and/or totaldiff are negative? I was hoping for a negative

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:07:05+00:00Added an answer on May 16, 2026 at 8:07 pm
    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What happens if I annotate a constructor parameter using @JsonProperty but the Json doesn't
what happens to my script in python that does not run through crontab every
What happens to http requests that are being processed when you stop or restart
Happens that I've ended up working on a big PHP program and I need
What happens is that I have a list of tags that needs to be
it happens with me that, I am working on a project with Eclipse. And
What happens when I use an ObjectInputStream to read in a serialized object that
It happens that, when writing some PHP code, I accidentally put a semicolon ;
I happens to read this http://code.google.com/speed/articles/optimizing-php.html It claims that this code $description = strip_tags($_POST['description']);
What happens in C if we do something like this in Java: temp.next =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.