T
Tim Rentsch
Larry Gates said:What does the standard mean when it speaks a a "semantic type?"
A "semantic type" is the type as determined by the semantics.
In most cases the semantic type is the same as the "evaluation
type", but for floating point these can be different from each
other. For example, if we have
double d, d0 = 0, d1 = 1;
d = d0 + d1;
the semantic type of the expression (d0 + d1) is (double),
but it might actually be evaulated as a (long double).
(The result is converted back to (double) for the assignment,
but the RHS expression is what's under consideration here.)
It seems strange (at least, it did to me when I found out
about it) that these can be different, especially since
the expressions (assuming a, b, and c are all of type
double)
(a + b) + c
and
(double)(a + b) + c
can result in different computations, because even though the
semantic type of (a + b) is (double), it might be evaluated
as a (long double), or even some unspecified type (with
precision greater than double) not even declarable in the
program, and casting that result to (double) will eliminate
any extra precision; in other words, the cast changes the
evaluation type back to be the same as the semantic type.