Skip to content

Commit c5aef44

Browse files
author
Colin Robertson
committed
Update to remove strict, add restrictions
1 parent def78bf commit c5aef44

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

docs/preprocessor/fenv-access.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "fenv_access pragma"
3-
ms.date: "08/29/2019"
3+
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."
4+
ms.date: "11/19/2019"
45
f1_keywords: ["vc-pragma.fenv_access", "fenv_access_CPP"]
56
helpviewer_keywords: ["pragmas, fenv_access", "fenv_access pragma"]
67
ms.assetid: 2ccea292-0ae4-42ce-9c67-cc189299857b
@@ -19,6 +20,14 @@ By default, **fenv_access** is **off**. If the compiler can assume that your cod
1920

2021
For more information on floating-point behavior, see [/fp (Specify Floating-Point Behavior)](../build/reference/fp-specify-floating-point-behavior.md).
2122

23+
There are restrictions on the ways you can use the **fenv_access** pragma in combination with other floating-point settings:
24+
25+
- You can't enable **fenv_access** unless precise semantics are enabled. Precise semantics can be enabled either by the [float_control](float-control.md) pragma, or by using the [/fp:precise](../build/reference/fp-specify-floating-point-behavior.md) or [/fp:strict](../build/reference/fp-specify-floating-point-behavior.md) compiler options. The compiler defaults to **/fp:precise** if no other floating-point command-line option is specified.
26+
27+
- You can't use **float_control** to disable precise semantics when **fenv_access(on)** is set.
28+
29+
These restrictions mean the order of some floating-point pragmas is significant. For more information, see [float_control](float-control.md).
30+
2231
The kinds of optimizations that are subject to **fenv_access** are:
2332

2433
- Global common subexpression elimination

docs/preprocessor/float-control.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: "float_control pragma"
3+
description: "Describes the usage and effects of the float_control pragma directive. The float_control directive controls the state of floating-point precise semantics and exception semantics at runtime."
34
ms.date: "11/18/2019"
45
f1_keywords: ["vc-pragma.float_control", "float_control_CPP"]
56
helpviewer_keywords: ["float_control pragma", "pragmas, float_control"]
@@ -12,54 +13,66 @@ Specifies floating-point behavior for a function.
1213
## Syntax
1314

1415
> **#pragma float_control**\
15-
> **#pragma float_control(** { **precise** | **strict** | **except** } **,** { **on** | **off** } [ **, push** ] **)**\
16+
> **#pragma float_control( precise,** { **on** | **off** } [ **, push** ] **)**\
17+
> **#pragma float_control( except,** { **on** | **off** } [ **, push** ] **)**\
1618
> **#pragma float_control(** { **push** | **pop** } **)**
1719
1820
## Options
1921

20-
**precise** | **strict** | **except**, **on** | **off**, **push**\
21-
Specifies floating-point behavior, which can be **precise**, **strict**, or **except**. The setting can either be **on** or **off**. For information on how these settings differ from the similarly named compiler options, see the Remarks section.
22+
**precise**, **on** | **off**, **push**\
23+
Specifies whether to enable (**on**) or disable (**off**) precise floating-point semantics. For information on how this option differs from the similarly named **/fp:precise** compiler option, see the Remarks section. If the optional **push** token is added, the current setting for **float_control** is pushed on to the internal compiler stack.
2224

23-
When **strict**, the settings for both **strict** and **except** are specified by the **on** or **off** setting.
25+
**except**, **on** | **off**, **push**\
26+
Specifies whether to enable (**on**) or disable (**off**) floating-point exception semantics. For information on how this option differs from the similarly named **/fp:except** compiler option, see the Remarks section. If the optional **push** token is added, the current setting for **float_control** is pushed on to the internal compiler stack.
2427

25-
If the optional **push** token is added, the current setting for **float_control** is pushed on to the internal compiler stack.
28+
**except** can only be set to **on** when **precise** is also set to **on**.
2629

2730
**push**\
28-
Push the current **float_control** setting on to the internal compiler stack
31+
Pushes the current **float_control** setting on to the internal compiler stack.
2932

3033
**pop**\
31-
Removes the **float_control** setting from the top of the internal compiler stack and makes that the new **float_control** setting.
34+
Removes the **float_control** setting from the top of the internal compiler stack, and makes that the new **float_control** setting.
3235

3336
## Remarks
3437

35-
The **strict** option is effectively the same as the combination of **precise** and **except**. If you set **strict** on or off, it also sets **except** on or off. **except** can only be set to **on** when **precise** or **strict** is also set to **on**.
38+
The **precise** and **except** options don't have exactly the same behavior as the [/fp](../build/reference/fp-specify-floating-point-behavior.md) compiler options of the same names. The **float_control** pragma only governs part of the floating-point behavior. It must be combined with [fp_contract](../preprocessor/fp-contract.md) and [fenv_access](../preprocessor/fenv-access.md) pragmas to recreate the **/fp** compiler options. The following table shows the equivalent pragma settings for each compiler option:
3639

37-
The **precise**, **strict**, and **except** options don't have exactly the same behavior as the [/fp](../build/reference/fp-specify-floating-point-behavior.md) compiler options of the same names. The **float_control** pragma only governs part of the floating-point behavior. It must be combined with [fp_contract](../preprocessor/fp-contract.md) and [fenv_access](../preprocessor/fenv-access.md) pragmas to recreate the `/fp` compiler options. The following table shows the equivalent pragma settings for each compiler option:
38-
39-
| | float_control(precise) | float_control(except) | fenv_access | fp_contract |
40+
| | float_control(precise, \*) | float_control(except, \*) | fp_contract(\*) | fenv_access(\*) |
4041
|-|-|-|-|-|
41-
|`/fp:fast`|off|off|off|on|
42-
|`/fp:precise`|on|off|off|on|
43-
|`/fp:strict`|on|on|on|off|
42+
| /fp:strict | on | on | off | on |
43+
| /fp:strict /fp:except- | on | off | off | on |
44+
| /fp:precise | on | off | on | off |
45+
| /fp:precise /fp:except | on | on | on | off |
46+
| /fp:fast | off | off | on | off |
47+
48+
In other words, you must use several pragmas in combination to emulate the **/fp:fast**, **/fp:precise**, **/fp:strict**, and **/fp:except** command-line options.
49+
50+
There are restrictions on the ways you can use the **float_control** and [fenv_access](../preprocessor/fenv-access.md) floating-point pragmas in combination:
51+
52+
- You can only use **float_control** to set **except** to **on** if 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.
53+
54+
- You can't use **float_control** to turn **precise** off when exception semantics are enabled, whether by a **float_control** pragma or a **/fp:except** compiler option.
55+
56+
- You can't enable [fenv_access](../preprocessor/fenv-access.md) unless precise semantics are enabled, whether by a **float_control** pragma or a compiler option.
4457

45-
For example, you must use several pragmas in combination to change from `/fp:fast` behavior to `/fp:precise` or `/fp:strict` and back again. To recreate [/fp:strict](../build/reference/fp-specify-floating-point-behavior.md), you must set **float_control(precise, on)**, **fenv_access(on)**, **float_control(except, on)**, and **fp_contract(off)**.
58+
- You can't use **float_control** to turn **precise** off when **fenv_access(on)** is set.
4659

47-
You can't use **float_control** to turn **precise** off when **except** is on. Similarly, **precise** can't be turned off when [fenv_access](../preprocessor/fenv-access.md) is on. That means, the order of some floating-point pragmas is significant. To go from a strict model to a fast model by using the **float_control** pragma, use the following code:
60+
These restrictions mean the order of some floating-point pragmas is significant. To go from a fast model to a strict model using the **float_control** and related pragmas, use the following code:
4861

4962
```cpp
50-
#pragma float_control(except, off)
51-
#pragma fenv_access(off)
52-
#pragma float_control(precise, off)
53-
#pragma fp_contract(on)
63+
#pragma float_control(precise, on) // enable precise semantics
64+
#pragma fenv_access(on) // enable environment sensitivity
65+
#pragma float_control(except, on) // enable exception semantics
66+
#pragma fp_contract(off) // disable contractions
5467
```
5568

56-
To go from fast model to a strict model with the **float_control** pragma, use the following code:
69+
To go from a strict model to a fast model by using the **float_control** pragma, use the following code:
5770

5871
```cpp
59-
#pragma float_control(precise, on)
60-
#pragma fenv_access(on)
61-
#pragma float_control(except, on)
62-
#pragma fp_contract(off)
72+
#pragma float_control(except, off) // disable exception semantics
73+
#pragma fenv_access(off) // disable environment sensitivity
74+
#pragma float_control(precise, off) // disable precise semantics
75+
#pragma fp_contract(on) // ensable contractions
6376
```
6477

6578
If no options are specified, **float_control** has no effect.

0 commit comments

Comments
 (0)