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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:33:07+00:00 2026-06-09T10:33:07+00:00

I would like to compute the average of three numbers, like: d = int(round((a

  • 0

I would like to compute the average of three numbers, like:

d = int(round((a + b + c) / 3.0))

Where a, b, c, d are integers.

Is it possible to get the same result using just integers?

I’m interested in this because of performance reasons, I assume doing the math using integers should be faster than using floats.

The example above converts the integers to floats, calculates the result, rounds it and converts back to integer. Is it possible to avoid the int <-> float conversions?

  • 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-06-09T10:33:09+00:00Added an answer on June 9, 2026 at 10:33 am

    Given the requirements for 1, 1, 2 -> 1; 1, 2, 2 -> 2 then this can be done using integer division.

    Using // for the integer division and n for number of elements.

    average = ( a+ b + c + .... + n//2 ) // n
    

    ie sum up all the values and then add a number to deal with rounding.

    As noted in @Henrik’s answer this assumes that all numbers are positive.

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

Sidebar

Related Questions

For given floating point numbers x and a , I would like to compute
I would like to compute the absolute difference of two integers. Naively, this is
Problem I would like to compute the following using numpy or scipy: Y =
I have data that I would like to compute some statistics with. The data
I would like to compute similarity between licenses' txt files so I could then
I would like to compute both the sine and co-sine of a value together
I have a List, and I would like to compute a double[360] containing the
I have two collections a and b . I would like to compute the
I have a huge graph that I would like to process using many machines.
I would like to compute time that spans between two particular moments: - start

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.