是< a> = b"相当于“a - b> = 0”? [英] Is "a >= b" equivalent to "a - b >= 0"?
问题描述
嗨!
表达式是a> = b相当于a - b> = 0在C / C ++中?
这个等价是IEEE / ANSI规则吗?或者这台机器/编译器
是否依赖?
欢迎任何参考!
先谢谢,Humberto 。
Hi!
Is the expression "a >= b" equivalent to "a - b >= 0" in C/C++?
Is this equivalence an IEEE/ANSI rule? Or is this machine/compiler
dependent?
Any references are welcome!
Thanks in advance, Humberto.
推荐答案
< hj ****** @ mat.puc-rio。 BR>在消息中写道
news:11 ********************* @ g44g2000cwa.googlegro ups.com ...
<hj******@mat.puc-rio.br> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
嗨!
表达式是a> = b相当于a - b> = 0在C / C ++中?
这个等价是IEEE / ANSI规则吗?或者这台机器/编译器是否依赖?
欢迎任何参考文献!
Hi!
Is the expression "a >= b" equivalent to "a - b >= 0" in C/C++?
Is this equivalence an IEEE/ANSI rule? Or is this machine/compiler
dependent?
Any references are welcome!
在C中,考虑如果发生以下情况: b == MIN_INT。
在C ++中,考虑任何运算符都可能过载,并且在每种情况下调用
不同的[set of]运算符。
- Risto -
In C, consider what happens if e.g. b==MIN_INT .
In C++, consider that any operator could be overloaded, and that
different [set of] operators is called in each case.
- Risto -
不一样。
考虑( ab)小于可能的最小值。
特殊情况是无符号类型。
marc
It is not the same.
Consider (a-b) is smaller than the smallest possible value.
A special case of this are unsigned types.
marc
< hj ****** @ mat.puc-rio.br>:
<hj******@mat.puc-rio.br>:
表达式是a> = b ;相当于a - b> = 0在C / C ++中?
这个等价是IEEE / ANSI规则吗?或者这台机器/编译器是否依赖?
Is the expression "a >= b" equivalent to "a - b >= 0" in C/C++?
Is this equivalence an IEEE/ANSI rule? Or is this machine/compiler
dependent?
如果a和b未签名,那么当然:不!
#include< stdio.h>
int main()
{
unsigned a = 1,b = 2;
printf("%d%c =%d \ n",> = b,"!=" [(a> = b)==(a - b> ; = 0)],a - b> =
0);
}
即使a和b也是如此是整数,答案是:不!
#include< stdio.h>
#include< limits.h>
int main()
{
int a = INT_MIN,b = INT_MAX;
printf("%d%c = %d \ n",a> = b,"!=" [(a> = b)==(a - b> = 0)],a - b> =
0);
}
Jirka
If a and b are unsigned, then of course : No!
#include <stdio.h>
int main()
{
unsigned a = 1, b = 2;
printf("%d %c= %d\n", a >= b, "!="[(a >= b) == (a - b >= 0)], a - b >=
0);
}
and even if a and b are ints, the answer is: No!
#include <stdio.h>
#include <limits.h>
int main()
{
int a = INT_MIN, b = INT_MAX;
printf("%d %c= %d\n", a >= b, "!="[(a >= b) == (a - b >= 0)], a - b >=
0);
}
Jirka
这篇关于是< a> = b"相当于“a - b> = 0”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!