pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/DefaultRyan/cpp-docs/blob/master/docs/preprocessor/fenv-access.md

3bd40328c.css" /> cpp-docs/docs/preprocessor/fenv-access.md at master · DefaultRyan/cpp-docs · GitHub
Skip to content

Latest commit

 

History

History
106 lines (76 loc) · 3.62 KB

File metadata and controls

106 lines (76 loc) · 3.62 KB
title fenv_access pragma
description Describes the usage and effects of the fenv_access pragma directive. The fenv_access directive controls access to the floating-point environment at runtime.
ms.date 11/19/2019
f1_keywords
vc-pragma.fenv_access
fenv_access_CPP
helpviewer_keywords
pragmas, fenv_access
fenv_access pragma
ms.assetid 2ccea292-0ae4-42ce-9c67-cc189299857b

fenv_access pragma

Disables (on) or enables (off) optimizations that could change floating-point environment flag tests and mode changes.

Syntax

#pragma fenv_access ( { on | off } )

Remarks

By default, fenv_access is off. The compiler assumes your code doesn't access or manipulate the floating-point environment. If environment access isn't required, the compiler can do more to optimize your floating-point code.

Enable fenv_access if your code tests floating-point status flags, exceptions, or sets control mode flags. The compiler disables floating-point optimizations, so your code can access the floating-point environment consistently.

The [/fp:strict] command-line option automatically enables fenv_access. For more information on this and other floating-point behavior, see /fp (Specify Floating-Point Behavior).

There are restrictions on the ways you can use the fenv_access pragma in combination with other floating-point settings:

  • You can't enable fenv_access unless precise semantics are enabled. Precise semantics can be enabled either by the float_control pragma, or by using the /fp:precise or /fp:strict compiler options. The compiler defaults to /fp:precise if no other floating-point command-line option is specified.

  • You can't use float_control to disable precise semantics when fenv_access(on) is set.

The kinds of optimizations that are subject to fenv_access are:

  • Global common subexpression elimination

  • Code motion

  • Constant folding

Other floating-point pragmas include:

Examples

This example sets fenv_access to on to set the floating-point control register for 24-bit precision:

// pragma_directive_fenv_access_x86.cpp
// compile with: /O2 /arch:IA32
// processor: x86
#include <stdio.h>
#include <float.h>
#include <errno.h>
#pragma fenv_access (on)

int main() {
   double z, b = 0.1, t = 0.1;
   unsigned int currentControl;
   errno_t err;

   err = _controlfp_s(&currentControl, _PC_24, _MCW_PC);
   if (err != 0) {
      printf_s("The function _controlfp_s failed!\n");
      return -1;
   }
   z = b * t;
   printf_s ("out=%.15e\n",z);
}
out=9.999999776482582e-03

If you comment out #pragma fenv_access (on) from the previous sample, the output is different. It's because the compiler does compile-time evaluation, which doesn't use the control mode.

// pragma_directive_fenv_access_2.cpp
// compile with: /O2 /arch:IA32
#include <stdio.h>
#include <float.h>

int main() {
   double z, b = 0.1, t = 0.1;
   unsigned int currentControl;
   errno_t err;

   err = _controlfp_s(&currentControl, _PC_24, _MCW_PC);
   if (err != 0) {
      printf_s("The function _controlfp_s failed!\n");
      return -1;
   }
   z = b * t;
   printf_s ("out=%.15e\n",z);
}
out=1.000000000000000e-02

See also

Pragma directives and the __pragma keyword

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy