Expression evaluation

The way in which a compiler on a platform issues code to evaluate expressions depends intimately on the underlying hardware architecture. Recall this code idiom, extracted from the example "Inner products using wide accumulators" on page 189:

      float  x = ...;
      double y = ...;
      y = y + (x * x);
On three different systems this can be evaluated three different ways. FPCE simplifies the discussion with its characterization of platforms by their minimum evaluation format--the narrowest type to which results (other than assignments) are computed. From this point of view:

A cast ensures at least double evaluation on all platforms:

      float  x = ...;
      double y = ...;
      y = y + ((double_t) x * x);
NOTE To guarantee the evaluation of narrow inner subexpressions to a wider type across all platforms, use explicit casting. You can determine the minimum evaluation format of an FPCE-compliant compiler on a particular platform from the macro
_MIN_EVAL_FORMAT, which evaluates to 0, 1, or 2 according to whether the format is float, double, or long double.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker