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

  • Home
  • SEARCH
  • 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 3393586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:04:05+00:00 2026-05-18T04:04:05+00:00

I am a hobbyist programming for an embedded application. The application requires speed. I

  • 0

I am a hobbyist programming for an embedded application. The application requires speed. I would like to determine whether or not a certain variable (call it “X”) has passed a certain percentage (call it “Y”) of another variable (call it “Z”).

X, Y, and Z can all change at runtime. Since I need speed I would like to do this using integer math as opposed to float, which incurs a speed penalty.

Are there any tricks for doing this? I am a self trained programmer so please excuse me if this is a well known problem with a well known solution.

Thank you!

  • 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-18T04:04:06+00:00Added an answer on May 18, 2026 at 4:04 am

    So what you want is to test 1*X > Z*Y there is nothing stopping you from doing exactly this, simply define 1 (and thus 100%) to be 10^decPlaces where decPlaces>=2 (otherwise you won’t have enough precision to do percentages as ints

    if you need calculations to be correct to within 4 d.p. if X = 10 then X_fixed_precision = 100000 if Y is 30% (0.3) then Y_fixed_precision=3000 and if Z=10000 then z_fixed_precision=100000000 this trick is called fixed precision arithmetic…

    If you want even better performace use powers of 2 instead of 10 (its harder to translate into exactly how many decimal places this gets you but should be somewhat faster)

    e.g. your code would probably look like

    if (ONE_FIXED_PRECISION * X_fixed_precision > Z_fixed_precision * Y_fixed_precision)
       // Do something
    

    where FOO_fixed_precision = FOO * ONE_FIXED_PRECISION

    Be careful to ensure that you aren’t going to get integer overflow there though – the Max value of X * ONE_FIXED_POINT * ONE_FIXED_POINT must be less than the maximum value you can store in a word (or double word if your using longer integer types)

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

Sidebar

Related Questions

I'm a hobbyist (and fairly new) programmer who has written several useful (to me)
I'm a long time hobbyist programmer interested in getting into web application development. I
So, if this question has been asked before, I'm sorry. I'm not exactly sure
I am a hobbyist programmer (started with VBA to make excel quicker) and have
Having been a hobbyist programmer for 3 years (mainly Python and C) and never
I'm writing a simple document management system for my work. I'm only a hobbyist
I'm a hobbyist, and started learning PHP last September solely to build a hobby
I'm a hobbyist programmer with a fair grasp of Python and I'm currently learning
I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much
I've been thinking quite some time about 'moving on' to MCU programming, but the

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.