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. Advertisements

  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. Advertisements

  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. Advertisements

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. Rob Mitchell

    [Q] fast way to negate?

    Rob Mitchell, Dec 13, 2005, in forum: Java
    Replies:
    0
    Views:
    458
    Rob Mitchell
    Dec 13, 2005
  2. M Welinder

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

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

    INT_MIN as decimal

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

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

    (unsigned)-INT_MIN

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

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

    Andy, Mar 18, 2009, in forum: C Programming
    Replies:
    8
    Views:
    2,152
    Keith Thompson
    Mar 18, 2009
  7. INT_MIN/-1

    , Oct 26, 2009, in forum: C Programming
    Replies:
    7
    Views:
    692
  8. Peter Nilsson

    Re: INT_MIN/-1

    Peter Nilsson, Oct 26, 2009, in forum: C Programming
    Replies:
    2
    Views:
    387
Loading...