473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

negate INT_MIN

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 '07 #1
2 2934
jz*******@gmail.com 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.

Feb 10 '07 #2
On 9 Feb 2007 20:26:54 -0800, "jz*******@gmail.com"
<jz*******@gmail.comwrote:
>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
Feb 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: M Welinder | last post by:
The title more or less says it all: in C99, is the value of INT_MIN % -1 well defined (when performed as signed integers) under the assumption of two-complement representation. Note, that...
15
by: Jordan Abel | last post by:
Say int is a 16-bit twos-complement type. Is the expression (-32768) actually negative? Or is it the unsigned int literal 32768 with the unary minus operator applied to it, resulting in the...
6
by: wij | last post by:
Hi: What is the protable way to negate an arithmetic integer? template<typename T> T negate(T t) { return -t; // <-- problem } On my Intel machines, taking negation like the above is...
1
by: shilpi.rustagi | last post by:
hi again.. i have a basic regular expression problem. we can negate a single charecter like this . but i want to negate a whole group e.g (<\tag>) hw can i do that can anyone help on it. ...
41
by: p_cricket_guy | last post by:
Please see this test program: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <limits.h> 4 5 int main (void) 6 { 7 int y = -2147483648; 8 int x = INT_MIN;
1
by: Mike | last post by:
I' d like to list all inactive clients. Inactive client is a client who hasn't had invoice for 2 months. I use INNER JOIN to join invoice view (vwDok4FSFZGrid) and clients addresses table...
8
by: Summercool | last post by:
somebody who is a regular expression guru... how do you negate a word and grep for all words that is tire but not snow tire or
30
by: viza | last post by:
Hi all int i= INT_MIN; unsigned int u= -i; Is u guaranteed to have the absolute value of INT_MIN? Why it might not: -i has type (int), and -INT_MIN might be more than INT_MAX.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.