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 7627367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:27:00+00:00 2026-05-31T05:27:00+00:00

(can skip this part just an explanation of the code below. my problems are

  • 0

(can skip this part just an explanation of the code below. my problems are under the code block.)

hi. i’m trying to algro for throttling loop cycles based on how much bandwidth the linux computer is using. i’m reading /proc/net/dev once a second and keeping track of the bytes transmitted in 2 variables. one is the last time it was checked the other is the recent time. from there subtracts the recent one from the last one to calculate how many bytes has been sent in 1 second.

from there i have the variables max_throttle, throttle, max_speed, and sleepp.

the idea is to increase or decrease sleepp depending on bandwidth being used. the less bandwidth the lower the delay and the higher the longer.

i am currently having to problems dealing with floats and ints. if i set all my variables to ints max_throttle becomes 0 always no matter what i set the others to and even if i initialize them.

also even though my if statement says “if sleepp is less then 0 return it to 0” it keeps going deeper and deeper into the negatives then levels out at aroung -540 with 0 bandwidth being used.

and the if(ii & 0x40) is for speed and usage control. in my application there will be no 1 second sleep so this code allows me to limit the sleepp from changing about once every 20-30 iterations. although im also having a problem with it where after the 2X iterations when it does trigger it continues to trigger every iteration after instead of only being true once and then being true again after 20-30 more iterations.

edit:: simpler test cast for my variable problem.

#include <stdio.h>

int main()
{
int max_t, max_s, throttle;

      max_s = 400;
      throttle = 90;
      max_t = max_s * (throttle / 100);
      printf("max throttle:%d\n", max_t);


return 0;
}
  • 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-31T05:27:01+00:00Added an answer on May 31, 2026 at 5:27 am

    In C, operator / is an integer division when used with integers only. Therefore, 90/100 = 0. In order to do floating-point division with integers, first convert them to floats (or double or other fp types).

    max_t = max_s * (int)(((float)throttle / 100.0)+0.5);
    

    The +0.5 is rounding before converting to int. You might want to consider some standard flooring functions, I don’t know your use case.

    Also note that the 100.0 is a float literal, whereas 100 would be an intger literal. So, although they seem identical, they are not.

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

Sidebar

Related Questions

You can actually just skip this first part cause it gets confusing, but I'll
if ConvertAll throw an exception on one element, can i just skip this element
Some background information, you can skip this part for the actual question this is
-> Short Introduction, you can SKIP this part I'm glad to be able to
If my Ajax requests set a X-Requested-With header, can I just skip the CSRF
I can't seem to get this one part right. I was given a input
Introduction a.k.a. what do I intend to do feel free to skip this part,
Title of the section: Faking Captured URLconf Values (For expert: you can just skip
You can skip to the bottom line if you don't care about the background:
Can you cast a List<int> to List<string> somehow? I know I could loop through

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.