Re: Unsigned Integer Overflow on Multiplication and Division

Discussion in 'C Programming' started by Eric Sosman, May 13, 2010.

  1. Eric Sosman

    Eric Sosman Guest

    On 5/13/2010 3:52 PM, Datesfat Chicks wrote:
    > What do the standards say about when you multiply two unsigned integers
    > and the result is too big?
    >
    > Similarly for addition?
    >
    > Is the compiler required to give you the actual result modulo 2^32 or
    > 2^64, or is the behavior pretty much undefined?


    What does your textbook say?

    --
    Eric Sosman
    lid
    Eric Sosman, May 13, 2010
    #1
    1. Advertising

  2. Eric Sosman

    Eric Sosman Guest

    On 5/13/2010 4:07 PM, Datesfat Chicks wrote:
    > "Eric Sosman" <> wrote in message
    > news:hshlhg$cdb$-september.org...
    >> On 5/13/2010 3:52 PM, Datesfat Chicks wrote:
    >>> What do the standards say about when you multiply two unsigned integers
    >>> and the result is too big?
    >>>
    >>> Similarly for addition?
    >>>
    >>> Is the compiler required to give you the actual result modulo 2^32 or
    >>> 2^64, or is the behavior pretty much undefined?

    >>
    >> What does your textbook say?

    >
    > Thanks for the humor, but this is not a homework problem.


    No implication of homework intended. Still: What does your
    textbook say? If you are such a C newbie that you need to ask so
    basic a question, you *need* a textbook. Really, truly. Get one.

    (Odd that someone unversed in the use of unsigned arithmetic
    is busily giving advice about it in another thread ...)

    > I'm implementing a pseudo-random number generator using a
    > microcontroller C compiler, and (as I'm sure you know) arithmetic modulo
    > 2^32 is what I'm looking for.
    >
    > I know what the library that comes with the compiler will do (it is
    > fairly obvious on a microcontroller because of the instruction set), but
    > I'm just curious if that is required behavior or coincidentally
    > convenient behavior.


    Perhaps your textbook will be helpful. If what it says makes
    no sense, try posting a confusing passage or two (and mention what
    textbook they come from).

    --
    Eric Sosman
    lid
    Eric Sosman, May 13, 2010
    #2
    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. Replies:
    1
    Views:
    783
    Thomas Matthews
    Jan 21, 2005
  2. Tim923
    Replies:
    4
    Views:
    516
    Tim923
    Apr 8, 2005
  3. William Hughes
    Replies:
    13
    Views:
    1,200
    Ben Bacarisse
    Mar 15, 2010
  4. Keith Thompson
    Replies:
    2
    Views:
    721
    Seebs
    May 13, 2010
  5. Francois Grieu
    Replies:
    0
    Views:
    282
    Francois Grieu
    Jun 8, 2010
Loading...

Share This Page