floating point constant folding
Hans van Eck
eck at cs.vu.nl
Wed Nov 14 19:58:32 AEST 1990
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?
>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.
The problem is that the standard (in 3.4) explicitely allows greater range
and precision for floating point expressions when a constant is required,
which seems to take higher precedence than the "as if" rule. What I do not
know is whether this rule may also be applied when a constant is not
required.
Perhaps a simple example is in place:
{ static double d = 0.3F;
double e = 0.3F;
In this example, d may may be initialised with a precision higher than that
of a float. Does that also hold for e?
Thanks in advance.
--
Hans van Eck, Dept. of Mathematics and Computer Science, Vrije Universiteit,
De Boelelaan 1081, 1081 HV Amsterdam, The Netherlands
Voice: +31 20 5485302 Email: eck at cs.vu.nl
More information about the Comp.std.c
mailing list