A
Andrew Koenig
In that case a - b yields +inf, and +inf >= 0.
Unless the implementation is set to trap. If it's not an IEEE
implementation, it might even trap by default.
In that case a - b yields +inf, and +inf >= 0.
Unless the implementation is set to trap. If it's not an IEEE
implementation, it might even trap by default.
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.
Read the replies, but am not positive if this was covered yet. Consider the
case where a is a very large double and b a very small value. With doubles
(and floates) and precision it could be the case where a - b does not
actually change a, even when b != 0.
so in that case (a >= b) != (a - b > 0) would wield true.
Walter Roberson said:Read the replies, but am not positive if this was covered yet. Consider
the
case where a is a very large double and b a very small value. With
doubles
(and floates) and precision it could be the case where a - b does not
actually change a, even when b != 0.so in that case (a >= b) != (a - b > 0) would wield true.
Hmmm, perhaps I am missing something in your answer:
If a - b does not change a then a - b is (to the precision of the
machine) equivilent to a, and the latter part of your logical expression
would become (a > 0) . You are postulating the case where a is a large
double, so a is either large and positive or large and negative.
(a > 0) will be true for the large and positive case, and false for the
large and negative case.
If we look at the large and positive case, with [under your conditions]
b as a very small value, then no matter which side of zero b happens to
be,
the large and positive a is going to be greater than the small b, so
(a >= b) will be true, and thus (a >= b) == (a - b > 0) for this case.
If we look at the large and negative case, with [under your conditions]
b as a very small value,l then again no matter which side of zero b
happens
to be, the large and negative a is going to be less than the small b,
so (a >= b) will be false, and thus (a >= b) == (a - b > 0) for this case.
Hence, under the conditions you indicate, with a large and b very small,
(a >= b) == (a - b > 0)
Indeed, forgot that one. The pleasure of having a != a.
Anti-objectivism?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.