floating point constant folding

Donald Lewine lewine at cheshirecat.rtp.dg.com
Thu Nov 15 01:34:03 AEST 1990


In article <1990Nov13.174025.1520 at zoo.toronto.edu>, henry at zoo.toronto.edu (Henry Spencer) writes:
|> In article <8191 at star.cs.vu.nl> eck at cs.vu.nl (Hans van Eck) writes:
|> >Is it allowed to evaluate constant floating point expressions with greater
|> >range and precision than that of the execution environment in contexts
|> >where a constant is not required?
|> >
|> >There are unexpected implications of both allowing and disallowing such
|> >folding, but I cannot find a statement in the standard that unambiguously
|> >says what a translator may or may not do.
|> 
|> I believe the relevant statement is the "as if" rule discussed in 2.1.2.3:
|> the compiler can do anything it pleases, provided the observable results
|> are the same.  Observable results include overflow exceptions and the values
|> of data items written out to files.  Evaluating constant floating-point
|> expressions at compile time using different floating-point hardware strikes
|> me as a minefield of difficulties.

See section 3.1.3 of the rationale: "In folding and converting
constants, an implementation must use at least as much precision as
is provided by the target environment.  However, it is not required
to used exactly the precision as the target, since this would require
a cross compiler to simulate target arithmetic at translation time."
 
In other words, the "as if" rule does not require getting a
bit-for-bit identical result. The "minefield of difficulties" can
be safely crossed.

--------------------------------------------------------------------
Donald A. Lewine                (508) 870-9008 Voice
Data General Corporation        (508) 366-0750 FAX
4400 Computer Drive. MS D112A
Westboro, MA 01580  U.S.A.

uucp: uunet!dg!lewine   Internet: lewine at cheshirecat.webo.dg.com



More information about the Comp.std.c mailing list