"semantic" in n1336.pdf

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.
 
T

Tim Rentsch

Ben Bacarisse said:
Section 3.8 defines:

constraint

restriction, either syntactic or semantic, by which the exposition
of language elements is to be interpreted

so it would be valid to view syntax errors as constraint violations
though the more common usage is view them as something that is
checkable at compile time but goes slightly beyond the syntax. This
is why, I think, the standard says (earlier) that it lays out the
"syntax, constraints and semantics" of C.

All constraints are checkable (and must be checked, in a conforming
implementation) at compile time. Some constraints are syntactic in
nature, and specified within the Standard using rules of syntax
(written in what is essentially a context free grammar); constraints
listed under a "Constraints" heading are semantic in nature, that is,
they are specified by prose rather than by rules of syntax, and they
may be impossible to express in a context free grammar.

Used as an adjective, "semantic" effectively means "pertaining to
program elements at a level above the level of syntax"; thus we may
have "semantic" modifying words like rules, restrictions, limitations,
or constraints.

Used as a noun, "semantics" means the "meaning" of a program, e.g.,
"the semantics of + is to produce the sum of its operands".
 
P

Phil Carmody

Tim Rentsch said:
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).

I would hope that it's permissible to evaluate it to even higher
precision than that, in order to accumulate processors with fused
multiply-add instructions.

Consider a*b - 1 for a=(1+eps), (b=1-eps), for small eps, for example.

Phil
 
T

Tim Rentsch

Phil Carmody said:
I would hope that it's permissible to evaluate it to even higher
precision than that, in order to accumulate processors with fused
multiply-add instructions.

Yes, as my earlier posting indicated, in a statement after
the above-quoted excerpt.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top