K
Keith Thompson
CBFalconer said:You snipped the demo, which I am re-inserting below. Note the
first sentence.
I acknowledge that the last part of my statement wasn't entirely
correct. Given an assignment:
obj = expr;
the value of expr is converted to the type of obj. If they're not
already of the same type, that conversion can change the value.
But this is not relevant to your claim that FP values represent
ranges.
[big snip]
No. That's true. Just look at the output of the demo. I inserted
3.33333333333333315e-01 into the float. I found 3.33333343e-01
there. The float can't hold 3.33333333333333315e-01. If you look
at the binary construction of the float, the reason becomes
obvious. It has nothing to do with processing. It has everything
to do with storing in a float. Bits have been chopped off.
Of course a float can't necessarily hold a value of type double. This
is not news to anyone.
How does this imply that, as you claim, it's not possible to
understand what a floating-point value is unless it's stored in an
object?
Given:
double d = some_value;
float f;
the assignment
f = d;
does two things: it converts the value of d from double to float, and
it stores the result of the conversion in f.
Yes, conversions can lose bits.
But a double value that is the result of evaluating an expression is
not altered when it is stored in a double object. The value you store
and the value you retrieve are the same.