Mail Archives: djgpp/1996/02/02/19:50:20
tanmoy AT qcd DOT lanl DOT gov (Tanmoy Bhattacharya) writes:
> I do not agree with this interpretation, as the footnote (technically,
> not part of the standard) clarifies: an assignment and cast both must
> truncate the result to the required precision.
Sorry, that footnote doesn't clarify matters. All the footnote says
is that the required conversions must be performed. In the example
we're talking about, there's no conversion to be performed, since
both sides of the assignment have `float' type.
Furthermore, even if there is a conversion, I don't see where the standard
requires that excess precision be discarded. All the standard requires is
that the result be ``represented exactly''; it doesn't say what it means
by this, and an implementation that keeps excess precision is certainly
representing _its_ result exactly. The standard explicitly licenses
excess precision, and never explicitly (or implicitly, as far as I can
see) requires excess precision to be discarded.
Also please see ANSI C 3.3.4, which says ``A cast that specifies no
conversion has no effect on the type or value of the expression'';
this means that an implementation with extra precision is not allowed
to discard it because of a cast of float to float. It is natural to
assume that assignment of float to float can behave similarly to a cast.
I realize that the standard is muddled in this area -- for example, the
Rationale contradicts it, and I've been told that the C Standard committee
may amend 3.3.4 because of the problem with floating point casts
(surely an implementation should be allowed to discard excess precision
whenever it wants to).
That being the case, I think it wise for users not to rely on the fine
points here, and my advice to the GCC implementers is to hold off on
changing GCC's behavior until the C Standard committee acts.
- Raw text -