Changing state globally

Most applications that alter rounding modes and exploit exception flags do so only within a local scope. If you require a global change, the system provides the class TFPEnvironmentModifier. This code sample sets rounding toward zero to accommodate a program written for an older mainframe that always rounded toward zero. (It is not unusual for programs designed for a particular kind of rounding to work correctly on platforms with different range and precision but offering the same rounding.)

      
    #pragma fenv_access on
      void InitializeRounding() {
          TFPEnvironmentModifier globalState(kFPTowardZero);
      }

[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