Division and Modular Reduction (Repost)

Discussion in 'C++' started by Jeffrey Walton, Jul 29, 2011.

  1. My apologies for a second post. Google did not pick up the original
    post and I don't have a true news reader.

    I'm building test cases for a third party library, and wanted a
    clarification. Searching the FAQ did not turn up hits for division and
    modulo or reduction [1].

    INT_MIN / -1 = overflow since the result is INT_MAX+1. For example
    (using int16 types):

    32768 = -32768 / -1

    Below, the result is within the reange of the datattype.

    32767 = -32768 % -1

    However Seacord tells us the result is undefined in CERT's Secure
    Programming Guide [2]. Also, I seem to recall that reduction is
    defined similar to division for consistency.

    What is the state of modular reduction (eg, INT_MIN % -1)?

    Jeff

    [1] http://www.parashift.com/c -faq-lite/
    [2]
    https://www.securecoding.cert.org/c...ations do not result in divide-by-zero errors
     
    Jeffrey Walton, Jul 29, 2011
    #1
    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:
    94
    Views:
    4,683
    ┬Ča\\/b
    Feb 9, 2007
  2. Jeffrey Walton

    Division and Modular Reduction

    Jeffrey Walton, Jul 29, 2011, in forum: C++
    Replies:
    1
    Views:
    396
    Victor Bazarov
    Jul 29, 2011
  3. jimbo1qaz
    Replies:
    12
    Views:
    361
  4. Cameron Simpson
    Replies:
    0
    Views:
    194
    Cameron Simpson
    Sep 7, 2012
  5. Mark Lawrence
    Replies:
    0
    Views:
    216
    Mark Lawrence
    Sep 7, 2012
Loading...

Share This Page