CBFalconer said:
Lets see if I can leap over the confusion. Consider a system with
a 4 bit significand, and an 8 bit exponent. The exponent uses the
value 128 to signify times 2 to the 0th power. We suppress the
msbit in the significand and replace it with a sign bit. The
significand can hold 0 through 15. Thus:
Exponent Significand Means
128 0 = 0x0 1.0
128 1 = 0x1 1.0 + 1/8
128 2 = 0x2 1.0 + 1/4
128 4 = 0x4 1.0 + 1/2
128 7 = 0x7 1.0 + 7/8
128 8 = 0x8 -1.0 /* the sign bit appeared */
128 9 = 0x9 -1.0 - 1/8
128 10 = 0xa -1.0 - 1/4
128 12 = 0xc -1.0 - 1/2
128 15 = 0xf -1.0 - 7/8
if we raise the exponent by 1, we double the value in Means. If we
lower it by one, we halve the values in Means. I hope we are
agreed so far.
I would not conflate the sign bit and the significand. I'd describe
this as a 3 bit normalised significand, but that is a detail.
Now, what is the EPSILON involved here. Obviously if we add 1/8 to
1.0, we get the next value. But that doesn't consider the rounding
done by the hardware. We only need to add 1/16 to get that
effect. What is the value 1/16 in that system?
127 0 1/2
126 0 1/4
125 0 1/8
124 0 1/16 /* Aha */
1.0 + 1/16 will round up to 1.0 + 1/8. /* assume usual rounding */
What does this result look like? See above. Only one least
significant bit is changed. So we have found EPSILON to be 1/16,
and the result from nextafter would be 1.0 + 1/8.
As Ike Naar has already pointed out, EPSILON is 1/8 in this system.
I'll skip your x*(1-EPSILON) to x*(1+EPSILON) description of the
ranges since it seems to be based on a misconception and consider the
other definition using xmax and ymin.
With x = 1, y = 1+1/8. What is the smallest real that will get stored
as 1+1/8? Note that this is a theoretical question. The FP system
never sees real numbers to convert, but we can extend what we expect
from it to answer the question. With at least one rounding model, any
real >= to 1+1/16 will convert to y so xmax might well be 1+1/16.
What about ymin? For any e > 0, 1+1/16-e will convert to x so what is
the largest such value? The limit is xmax and the simplest shorthand
is to say that ymin == xmax and describe the "ranges" as open or
(better) half-open intervals.
A different rounding model will make ymin = 1+1/6 and xmax the limit
of 1+1/16+e as e -> 0. Because the reals are closed under such limit
operations, your definitions defined a unique single value at the
boundary between the "ranges" represented by FP values.
<snip>