negate INT_MIN

Discussion in 'C Programming' started by jzhang918@gmail.com, Feb 10, 2007.

  1. Guest

    Hi,

    Should f(INT_MIN) return 0 according to the C99 for the following
    function f (), or its result is undefined?

    int f(int i)
    {
    i = i > 0 ? i : -i;
    if (i<0)
    return 0;
    else
    return 1;
    }

    Thanks!
    Jie
    , Feb 10, 2007
    #1
    1. Advertising

  2. wrote:
    > Hi,
    >
    > Should f(INT_MIN) return 0 according to the C99 for the following
    > function f (), or its result is undefined?
    >
    > int f(int i)
    > {
    > i = i > 0 ? i : -i;
    > if (i<0)
    > return 0;
    > else
    > return 1;
    > }


    It should return 1 when INT_MIN is equal to -INT_MAX. The behaviour
    (not just the result) is undefined when INT_MIN is equal to -INT_MAX -
    1.
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Feb 10, 2007
    #2
    1. Advertising

  3. ¬a\\/b Guest

    On 9 Feb 2007 20:26:54 -0800, ""
    <> wrote:
    >Hi,
    >
    >Should f(INT_MIN) return 0 according to the C99 for the following
    >function f (), or its result is undefined?
    >
    >int f(int i)
    >{
    > i = i > 0 ? i : -i;
    > if (i<0)
    > return 0;
    > else
    > return 1;
    >}


    it seems undefined
    if i see a char -128..127
    -(-128)==?

    >Thanks!
    >Jie
    ¬a\\/b, Feb 10, 2007
    #3
    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. M Welinder

    C99: Is "INT_MIN % -1" well defined?

    M Welinder, Aug 5, 2004, in forum: C Programming
    Replies:
    6
    Views:
    348
    Dik T. Winter
    Aug 7, 2004
  2. Jordan Abel

    INT_MIN as decimal

    Jordan Abel, Mar 8, 2006, in forum: C Programming
    Replies:
    15
    Views:
    658
    Peter Nilsson
    Mar 9, 2006
  3. INT_MIN and compiler diagnostic

    , Feb 28, 2007, in forum: C Programming
    Replies:
    41
    Views:
    1,187
    Chris Torek
    Mar 26, 2007
  4. viza

    (unsigned)-INT_MIN

    viza, Jul 21, 2008, in forum: C Programming
    Replies:
    22
    Views:
    1,014
    Keith Thompson
    Jul 26, 2008
  5. Andy

    (INT_MIN -1) > 0 equals to 0??

    Andy, Mar 18, 2009, in forum: C Programming
    Replies:
    8
    Views:
    1,607
    Keith Thompson
    Mar 18, 2009
Loading...

Share This Page