R
Robert Latest
Hi guys,
I'm sure this has been beaten to death on this newsgroup, but I can't
find it in the CLC FAQ.
Consider the following code:
--------
double x = some_value_from_somewhere;
double y = x;
if ((x == y) && ((x - y) == 0)) {
puts("This is what I want");
}
--------
Will the condition in the if statement always, unconditionally, and
portably evaluate to a true value?
I know that I normally cannot rely on testing floats for equality; I
just wonder if this holds also when the variables in question are
explicitly set to the same value in the source.
I feel a bit stupid even typing this question since I can't imagine how
x and y could possibly come out as unequal by any implementation's
standard, but since I've been bitten quite a few times by things that
seemed obvious but turned out to be different (for, in retrospect, very
sensible reasons) I feel that I'd rather ask.
Thanks,
robert
I'm sure this has been beaten to death on this newsgroup, but I can't
find it in the CLC FAQ.
Consider the following code:
--------
double x = some_value_from_somewhere;
double y = x;
if ((x == y) && ((x - y) == 0)) {
puts("This is what I want");
}
--------
Will the condition in the if statement always, unconditionally, and
portably evaluate to a true value?
I know that I normally cannot rely on testing floats for equality; I
just wonder if this holds also when the variables in question are
explicitly set to the same value in the source.
I feel a bit stupid even typing this question since I can't imagine how
x and y could possibly come out as unequal by any implementation's
standard, but since I've been bitten quite a few times by things that
seemed obvious but turned out to be different (for, in retrospect, very
sensible reasons) I feel that I'd rather ask.
Thanks,
robert