Beej Jorgensen said:
CBFalconer said:
Is the interval actually defined for anything other than 1.0?
Yes, but it's implementation-defined. The floating-point model in C99
5.2.4.2.2 has a number of parameters (exponent range, precision,
etc.).
"You see this? This is this." CBF means the value that was attempted
to be stored, not the value that was stored.
But what does "attempted" mean? Programs don't attempt to do things.
I think the ultimate answer is in c99 6.3.1.4p2, 6.3.1.5p2, and
probably elsewhere:
# If the value being converted is in the range of values that can be
# represented but cannot be represented exactly, the result is either
# the nearest higher or nearest lower representable value, chosen in an
# implementation-defined manner.
That's talking about conversions. There's similar (but looser)
wording for arithmetic operators (+ - * /) and for the functions in
<math.h>. But all this stuff happens before the resulting value is
stored.
Regardless of how a floating-point value is computed, the result is
some unique value.
The Standard, as such, is defining a relationship between an
unrepresentable subspace and its neighboring representable values:
s t
A|-----|B|-----|C
It says if a conversion ends up in unrepresentable subspace s, the value
stored is A or B. If a conversion ends up in subspace t, the value
stored cannot be A--it must be B or C.
So if I tell you the stored value is EXACTLY B, you really can't tell me
what mathematical value led to that result, but you can tell me with
certainty that it fell somewhere between A and C. This is my read on
what CBF is saying.
Right, but I've been discussing the result itself, not what led to it.
It could just as well have been produced by treating a double object
as an array of unsigned char and using system-specific knowledge to
construct the desired representation.
Yet the value ultimately stored is EXACTLY B. This is my read of what
everyone else is saying. I don't think CBF actually disagrees with
this.
I don't think CBF actually understands this.
Floating-point operations generally yield approximate values; I think
everyone understands this.
*Some* floating-point operations can yield exact values. For example,
1.0 + 1.0 == 2.0 in any sane implementation, though I don't think the
standard quite managers to guarantee this. But I think we can at
least assume that the constant 1.0 yields the value one.
So we can discuss the range of values that might be produced by a
given floating-point expression. But any FP expression will yield
just one value in that range, and when that value is stored in an
object, all information about the range is discarded, leaving only the
unique representable floating-point value, which by definition
(5.2.4.2.2) denotes a single unique real number. And that, I think,
is what CBF has been having trouble with.