integer overflow

Discussion in 'Python' started by Chad Haynes, Feb 5, 2004.

  1. Chad Haynes

    Chad Haynes Guest

    I got an odd error which I cannot explain and cannot seem to reproduce.
    The following statement

    lst[0] = num

    produced this error

    OverflowError: unsigned short is greater than maximum

    The number was around 65536 so it makes sense that it would overflow a
    short, but why is it trying to force it into a short integer?

    -Chad
    Chad Haynes, Feb 5, 2004
    #1
    1. Advertising

  2. Chad Haynes

    Jp Calderone Guest

    On Thu, Feb 05, 2004 at 10:58:28AM -0500, Chad Haynes wrote:
    > I got an odd error which I cannot explain and cannot seem to reproduce.
    > The following statement
    >
    > lst[0] = num
    >
    > produced this error
    >
    > OverflowError: unsigned short is greater than maximum
    >
    > The number was around 65536 so it makes sense that it would overflow a
    > short, but why is it trying to force it into a short integer?


    >>> import array
    >>> a = array.array('h', [0])
    >>> a[0] = 10000000

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    OverflowError: signed short integer is greater than maximum

    Jp
    Jp Calderone, Feb 5, 2004
    #2
    1. Advertising

  3. Chad Haynes <> writes:

    > I got an odd error which I cannot explain and cannot seem to reproduce.
    > The following statement
    >
    > lst[0] = num
    >
    > produced this error
    >
    > OverflowError: unsigned short is greater than maximum
    >
    > The number was around 65536 so it makes sense that it would overflow a
    > short, but why is it trying to force it into a short integer?


    Is lst an array.array('h') or something (numarray...)?

    Cheers,
    mwh

    --
    An encyclopedia is about being as accurate as it can, not being
    evenly misinformed. -- Coby Beck, comp.lang.lisp
    Michael Hudson, Feb 5, 2004
    #3
  4. Chad Haynes

    Chad Haynes Guest

    Michael Hudson wrote:

    > Chad Haynes <> writes:
    >
    >
    >>I got an odd error which I cannot explain and cannot seem to reproduce.
    >>The following statement
    >>
    >> lst[0] = num
    >>
    >>produced this error
    >>
    >> OverflowError: unsigned short is greater than maximum
    >>
    >>The number was around 65536 so it makes sense that it would overflow a
    >>short, but why is it trying to force it into a short integer?

    >
    >
    > Is lst an array.array('h') or something (numarray...)?


    Nope, its just a regular list

    >
    > Cheers,
    > mwh
    >
    Chad Haynes, Feb 5, 2004
    #4
  5. Chad Haynes <> writes:

    > Michael Hudson wrote:
    >
    > > Chad Haynes <> writes:
    > >
    > >>I got an odd error which I cannot explain and cannot seem to reproduce.
    > >>The following statement
    > >>
    > >> lst[0] = num
    > >>
    > >>produced this error
    > >>
    > >> OverflowError: unsigned short is greater than maximum
    > >>
    > >>The number was around 65536 so it makes sense that it would overflow a
    > >>short, but why is it trying to force it into a short integer?

    > > Is lst an array.array('h') or something (numarray...)?

    >
    > Nope, its just a regular list


    Code, please.

    Cheers,
    mwh

    --
    The snakes are optional, as are the electrodes, the molten lead
    and the ritual buggering by syphilitic warthogs.
    -- Tanuki the Raccoon-dog, asr
    Michael Hudson, Feb 5, 2004
    #5
  6. Chad Haynes

    Terry Reedy Guest

    "Chad Haynes" <> wrote in message
    news:...
    > Michael Hudson wrote:
    >
    > > Chad Haynes <> writes:
    > >> lst[0] = num
    > >>
    > >>produced this error
    > >>
    > >> OverflowError: unsigned short is greater than maximum
    > >>
    > >>The number was around 65536 so it makes sense that it would overflow a
    > >>short, but why is it trying to force it into a short integer?

    > >
    > >
    > > Is lst an array.array('h') or something (numarray...)?

    >
    > Nope, its just a regular list


    Suggestion: open interactive window, type in minimal lines of code needed
    to reproduce error, then cut and post entire window, including header that
    identifies your particular binary. Also mention the source of binary (who
    compiled, you or someone else).

    TJR
    Terry Reedy, Feb 5, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bartek
    Replies:
    3
    Views:
    3,090
    bartek
    Feb 6, 2004
  2. John Black
    Replies:
    1
    Views:
    4,507
    John Harrison
    Apr 15, 2004
  3. deancoo

    integer or long overflow...

    deancoo, Mar 5, 2005, in forum: C++
    Replies:
    11
    Views:
    763
    Pete Becker
    Mar 5, 2005
  4. Enrico 'Trippo' Porreca

    Integer overflow

    Enrico 'Trippo' Porreca, Aug 21, 2003, in forum: C Programming
    Replies:
    9
    Views:
    412
  5. Ashutosh Iddya

    integer overflow

    Ashutosh Iddya, Apr 16, 2004, in forum: C Programming
    Replies:
    25
    Views:
    922
    RoSsIaCrIiLoIA
    Apr 24, 2004
Loading...

Share This Page