CBFalconer said:
Keith Thompson wrote: [...]
Then the division is evaluated. The division operation takes two
double operands, with values 1.0 and 3.0, and yields a floating-point
result; on my system, that result is exactly
0.333333333333333314829616256247390992939472198486328125 .
Which is NOT 1.0/3.0.
It's not 1.0/3.0 if you take 1.0/3.0 to be a real expression. It *is*
1.0/3.0 if you take 1.0/3.0 to be a C expression of type double. (On
my system; the exact value may vary on other systems.)
1/3 (integer division), 1.0/3.0 (FP division), and 1.0/3.0
(mathematical real division, not supported in C) are three different
expressions with three different values.
You can supply the two integers as integers
in a structure, for example. You can use that to build a whole
rational arithmetic system, but we won't bother.
Good, because it's irrelevant. There are numerous ways to represent
numbers in C. The way we're talking about here is the built-in
floating-point facility, not some other facility that might be
implemented in C.
Similarly, the fact that I can implement a symbolic algebra system in
which pi is represented as, say, { is_pi => 1 } isn't relevant to the
question of whether C floating-point can represent transcendental
numbers.
We're talking about what C floating-point can represent, not what C
can represent.
The point is that
the exact value has been specified, and the fp-processing has
altered it. My 'range' process on the fp-object-value ties it
down.
No, the exact value one-third was never specified. It could be
specified using mathematical real division, but C doesn't provide
mathematical real division. It provides floating-point division,
which yields floating-point results that differ from the corresponding
(unsupported) real division.
BTW, there is no point in printing digits from your double value
past the length specified by DBL_DIG (see float.h). See my earlier
answer to you and the example showing how the fp-system alters
values.
Yes, there is a point. The 55 digits denote the exact stored
floating-point value. Fewer digits are adequate for most purposes,
but they would not denote the exact stored value.
Note that the failure of decimal FP constants to specify exact values
is exactly why hexadecimal FP constants were introduced in C99.