K
Keith Thompson
[...]CBFalconer said:x is a double. So is the expression (1.0). So they represent the
same range.
I think you're saying that the above code may not print "Oops!",
but you didn't actually say so. Can you confirm that?
In the following, I will ignore NaNs and infinities.
So in your model, (x < y) must yield 0 if both x and y represent
the same range, even though some values in the range of x are less
than some values in the range of y. Presumably (x < y) yields 1 if
and only if each value in the range of x is less than each value
in the range of y. And (x == y) if and only if both ranges are
exactly the same. Is that correct?
Is it ever possible for one floating-point value's range to be a
proper subset of another floating-point value's range? May two
such ranges ever overlap without being identical?
The standard clearly states that the accuracy of floating-point
*operations* is implementation-defined (C99 5.2.4.2.2p5).
It makes no such statement about the accuracy or range of stored
floating-point values. Is the range represented by a stored
floating-point value implementation-defined? May the range be wide
enough to include other exactly representable floating-point values?
For example, may the range represented by the stored value 1.0
include 1.0+DBL_EPSILON? If not, what in the standard forbids it?
What exactly are the bounds of the range represented by the stored
value 1.0?
I encourage you to answer these questions with reference to the
standard, not based on what you think the answers *should* be.
If the standard intended each floating-point value to represent a
range, wouldn't it clearly answer questions like these? Why doesn't
it?
Assume, for the sake of argument, a language very similar to
(your conception of) C, except that each floating-point number
represents a single real value (actually a rational value) rather
than a range of values. Do you agree that such a language would
be consistent, even if you dislike it? Can you present a program
that would behave differently in this hypothetical language than in
(your conception of) C? To be clear, this "hypothetical language"
is, in my opinion, simply standard C.