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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:27:50+00:00 2026-05-26T09:27:50+00:00

Python 2 has two integer datatypes int and long , and automatically converts between

  • 0

Python 2 has two integer datatypes int and long, and automatically converts between them as necessary, especially in order to avoid integer overflow.

I am simulating a C function in Python and am wondering if there are standard ways to re-enable integer overflow. For the nonce, I’ve used

overflow_point = maxint + 1
if value > overflow_point:
    value -= 2 * overflow_point

Is there a more standard way to do the same thing?

  • 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-26T09:27:50+00:00Added an answer on May 26, 2026 at 9:27 am

    I think the basic idea is sound, but needs some tweaks:

    1. your function doesn’t overflow on sys.maxint+1, but it should;
    2. sys.maxint can be exceeded several times over as a result of a single operation;
    3. negative values below -sys.maxint-1 also need to be considered.

    With this in mind, I came up with the following:

    import sys
    
    def int_overflow(val):
      if not -sys.maxint-1 <= val <= sys.maxint:
        val = (val + (sys.maxint + 1)) % (2 * (sys.maxint + 1)) - sys.maxint - 1
      return val
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python has a function urljoin that takes two URLs and concatenates them intelligently. Is
Python has a function urljoin that takes two URLs and concatenates them intelligently. Is
Python 2.x has two ways to overload comparison operators, __cmp__ or the rich comparison
My Google-fu has failed me. In Python, are the following two tests for equality
Python 2.7 has two different disk image installers for Mac OS X. My questions
My client has two offices in Germany and USA and a python program should
Python has a standard library module ftplib to run FTP communications. It has two
I'm using Python 2.6 and Windows Server 2008 . The server has two IP
My python program has two calls to raw_input() The first raw_input() is to take
I have a model called Story that has two integer fields called views and

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.