标签:
先来谈谈补码的非
int tadd_ok(char x,char y)
{
char sum = (char)x + y;
printf("sum is %d,y is %d\n",sum,y);
int neg_over = x < 0 && y < 0 && sum >= 0;
int pos_over = x >= 0 && y >= 0 && sum < 0;
return !neg_over && !pos_over;
}
int tsub_ok(int x, int y)
{
if (y < 0 && -y < 0) /* y是否为最小负数 */
{
return x < 1;
}
else
return tadd_ok(x, -y);
}
标签:
原文地址:http://www.cnblogs.com/gain/p/5407599.html