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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:20:56+00:00 2026-05-20T02:20:56+00:00

This came up in an interview recently (the concept) and I was discussing it

  • 0

This came up in an interview recently (the concept) and I was discussing it with a friend today. Here’s the idea:

Suppose you are calculating the dot product of a three-dimensional vector. Simple function would be “return (x1*x2)+(y1*y2)+(z1*z2)”.

However, if the first and second term are large positive numbers, they could overflow even if they answer is within the acceptable range. For example, let’s say the integer limit is 128. 100 + 100 – 80 = 120, but if you do the first two additions first you’ll overflow.

In a university class this came up on a C assignment where we were calculating something that we’d probably done a thousand times before but had never paid attention to overflow (this was the part when we were learning about writing sanitary code), like taking an average or something of the sort.

Anyone have any idea in what context this could have happened? I know it was some situation where you had to use comparisons either before or instead of addition/subtraction to avoid this overflow

  • 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-20T02:20:57+00:00Added an answer on May 20, 2026 at 2:20 am

    Binary search is a classic example. Many many implementations do a computation that’s basically finding the midpoint of two indices:
    (high + low) / 2
    but if high and low are each near Integer.MAX_VALUE or the equivalent for your language, high+low overflows before the divide can happen, and your answer is wrong:

    http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html

    Easy fix is in that case to do:
    high/2 + low/2
    instead, which doesn’t overflow but it’s an almost universal bug in implementations of binary search, and it’s the very first thing to pop into mind when someone talks about an overflow in a computation that should result in a non-overflowing value.

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

Sidebar

Related Questions

I came across this question on an interview questions thread. Here is the question:
I recently had this question in an interview and this is what I came
This came up as a question I asked in an interview recently as something
I recently came across this interview question (posted in a forum somehwere... looks like
Today I came across a Interview where I was put this question, What design
I am preparing for my interview and came across this question: Consider that i
This question was asked in an interview. First, I came up with B-tree. He
This came up recently in a class for which I am a teaching assistant.
Got this question in an interview today, and its optimized solution stopped me cold
I came across this code in an interview. int main() { int **p; p

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.