You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specifies how the compiler treats floating-point expressions, optimizations, and exceptions. The **/fp** options specify whether the generated code allows floating-point environment changes to the rounding mode, exception masks, and subnormal behavior, and whether floating-point status checks return current, accurate results. It controls whether the compiler generates code that maintains source operation and expression ordering and conforms to the standard for NaN propagation, or if it instead generates more efficient code that may reorder or combine operations and use simplifying algebraic transformations that aren't allowed by the standard.
11
+
Specifies how the compiler treats floating-point expressions, optimizations, and exceptions. The **`/fp`** options specify whether the generated code allows floating-point environment changes to the rounding mode, exception masks, and subnormal behavior, and whether floating-point status checks return current, accurate results. It controls whether the compiler generates code that maintains source operation and expression order, and conforms to the standard for NaN propagation. Or, if it instead generates more efficient code that may reorder or combine operations and use simplifying algebraic transformations that aren't allowed by the IEEE-754 standard.
12
12
13
13
## Syntax
14
14
15
-
::: moniker range=">msvc-160"
15
+
::: moniker range=">=msvc-170"
16
16
17
17
**`/fp:contract`**\
18
18
**`/fp:except`**\[**`-`**]\
@@ -21,6 +21,7 @@ Specifies how the compiler treats floating-point expressions, optimizations, and
21
21
**`/fp:strict`**
22
22
23
23
::: moniker-end
24
+
24
25
::: moniker range="<=msvc-160"
25
26
26
27
**`/fp:except`**\[**`-`**]\
@@ -32,7 +33,7 @@ Specifies how the compiler treats floating-point expressions, optimizations, and
32
33
33
34
### Arguments
34
35
35
-
::: moniker range=">msvc-160"
36
+
::: moniker range=">=msvc-170"
36
37
37
38
#### <aname="contract"></a> `/fp:contract`
38
39
@@ -50,7 +51,7 @@ By default, the compiler uses **`/fp:precise`** behavior.
50
51
51
52
Under **`/fp:precise`**, the compiler preserves the source expression ordering and rounding properties of floating-point code when it generates and optimizes object code for the target machine. The compiler rounds to source code precision at four specific points during expression evaluation: at assignments, typecasts, when floating-point arguments get passed to a function call, and when a function call returns a floating-point value. Intermediate computations may be performed at machine precision. Typecasts can be used to explicitly round intermediate computations.
52
53
53
-
::: moniker range=">msvc-160"
54
+
::: moniker range=">=msvc-170"
54
55
55
56
The compiler doesn't perform algebraic transformations on floating-point expressions, such as reassociation or distribution, unless it can guarantee the transformation produces a bitwise identical result. Expressions that involve special values (NaN, +infinity, -infinity, -0.0) are processed according to IEEE-754 specifications. For example, `x != x` evaluates to **`true`** if `x` is NaN. Floating-point contractions aren't generated by default under **`/fp:precise`**. This behavior is new in Visual Studio 2022. Previous compiler versions could generate contractions by default under **`/fp:precise`**.
56
57
@@ -61,7 +62,7 @@ The compiler doesn't perform algebraic transformations on floating-point express
61
62
62
63
::: moniker-end
63
64
64
-
The compiler generates code intended to run in the [default floating-point environment](#the-default-floating-point-environment). It also assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code doesn't unmask floating-point exceptions, read or write floating-point status registers, or change rounding modes.
65
+
The compiler generates code intended to run in the [default floating-point environment](#the-default-floating-point-environment). It also assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code: leaves floating-point exceptions masked, doesn't read or write floating-point status registers, and doesn't change rounding modes.
65
66
66
67
If your floating-point code doesn't depend on the order of operations and expressions in your floating-point statements (for example, if you don't care whether `a * b + a * c` is computed as `(b + c) * a` or `2 * a` as `a + a`), consider the [`/fp:fast`](#fast) option, which can produce faster, more efficient code. If your code both depends on the order of operations and expressions, and accesses or alters the floating-point environment (for example, to change rounding modes or to trap floating-point exceptions), use [`/fp:strict`](#strict).
67
68
@@ -77,9 +78,9 @@ Under **`/fp:strict`**, the compiler generates code that allows the program to s
77
78
78
79
The **`/fp:fast`** option allows the compiler to reorder, combine, or simplify floating-point operations to optimize floating-point code for speed and space. The compiler may omit rounding at assignment statements, typecasts, or function calls. It may reorder operations or make algebraic transforms, for example, by use of associative and distributive laws. It may reorder code even if such transformations result in observably different rounding behavior. Because of this enhanced optimization, the result of some floating-point computations may differ from the ones produced by other **`/fp`** options. Special values (NaN, +infinity, -infinity, -0.0) may not be propagated or behave strictly according to the IEEE-754 standard. Floating-point contractions may be generated under **`/fp:fast`**. The compiler is still bound by the underlying architecture under **`/fp:fast`**, and more optimizations may be available through use of the [`/arch`](arch-minimum-cpu-architecture.md) option.
79
80
80
-
Under **`/fp:fast`**, the compiler generates code intended to run in the default floating-point environment and assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code doesn't unmask floating-point exceptions, read or write floating-point status registers, or change rounding modes.
81
+
Under **`/fp:fast`**, the compiler generates code intended to run in the default floating-point environment and assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code: leaves floating-point exceptions masked, doesn't read or write floating-point status registers, and doesn't change rounding modes.
81
82
82
-
`/fp:fast` is intended for programs that don't require strict source code ordering and rounding of floating-point expressions, and don't rely on the standard rules for handling special values such as NaN. If your floating-point code requires preservation of source code ordering and rounding, or relies on standard behavior of special values, use [`/fp:precise`](#precise). If your code accesses or modifies the floating-point environment to change rounding modes, unmask floating-point exceptions, or check floating-point status, use [`/fp:strict`](#strict).
83
+
**`/fp:fast`** is intended for programs that don't require strict source code ordering and rounding of floating-point expressions, and don't rely on the standard rules for handling special values such as `NaN`. If your floating-point code requires preservation of source code ordering and rounding, or relies on standard behavior of special values, use [`/fp:precise`](#precise). If your code accesses or modifies the floating-point environment to change rounding modes, unmask floating-point exceptions, or check floating-point status, use [`/fp:strict`](#strict).
83
84
84
85
#### <aname="except"></a> `/fp:except`
85
86
@@ -97,24 +98,26 @@ The [`/Za`](za-ze-disable-language-extensions.md) (ANSI compatibility) option is
97
98
98
99
The compiler provides three pragma directives to override the floating-point behavior specified on the command line: [`float_control`](../../preprocessor/float-control.md), [`fenv_access`](../../preprocessor/fenv-access.md), and [`fp_contract`](../../preprocessor/fp-contract.md). You can use these directives to control floating-point behavior at function-level, not within a function. These directives don't correspond directly to the **`/fp`** options. This table shows how the **`/fp`** options and pragma directives map to each other. For more information, see the documentation for the individual options and pragma directives.
# `/fpcvt` (Floating-point to integer conversion compatibility)
9
+
10
+
Specifies how the compiler treats floating-point conversions to integer types.
11
+
12
+
## Syntax
13
+
14
+
> **`/fpcvt:IA`**\
15
+
> **`/fpcvt:BC`**
16
+
17
+
### Arguments
18
+
19
+
#### <aname="fpcvt-ia"></a> `/fpcvt:IA`
20
+
21
+
The **`/fpcvt:IA`** option tells the compiler to convert floating point values to integers so the results are compatible with the Intel AVX-512 conversion instructions. This behavior is the usual behavior in Visual Studio 2019 for x86 targets.
22
+
23
+
#### <aname="fpcvt-bc"></a> `/fpcvt:BC`
24
+
25
+
The **`/fpcvt:BC`** option tells the compiler to convert floating point values to unsigned integers so the results are compatible with the Visual Studio 2017 and earlier compilers. This behavior is the default in Visual Studio 2022.
26
+
27
+
## Remarks
28
+
29
+
In Visual Studio 2019 version 16.8 and later versions, the **`/fpcvt`** compiler option can be used to control the results of floating-point to integer conversions. The **`/fpcvt:BC`** option specifies the default behavior of Visual Studio 2022, which is the same as the behavior of Visual Studio 2017 and earlier versions. The **`/fpcvt:IA`** option specifies behavior compatible with Intel Architecture (IA) AVX-512 conversion instruction behavior. This option can be used with either 32-bit x86 or 64-bit x64 targets, and it applies whether [`/arch:AVX512`](arch-x86.md) is specified or not.
30
+
31
+
For Visual Studio 2019, the default behavior for x64 targets is consistent with **`/fpcvt:BC`** unless **`/arch:AVX512`** is specified. Usually, the behavior for x86 targets is consistent with **`/fpcvt:IA`**, except under **`/arch:IA32`**, **`/arch:SSE`**, or sometimes where the result of a function call is directly converted to an unsigned integer. Use of **`/fpcvt`** overrides the default, so all conversions are handled consistently on either target. The behavior of conversions for ARM and ARM64 targets isn't consistent with either **`/fpcvt:BC`** or **`/fpcvt:IA`**.
32
+
33
+
Standard C++ specifies that if a floating-point value can be exactly represented in an integer type, conversion from floating-point to that integer type must return that value. Otherwise, any behavior at all is allowed. Both **`/fpcvt`** options conform with Standard C++. The only difference is in what values are returned for invalid source values.
34
+
35
+
The **`/fpcvt:IA`** option causes any invalid conversion to return a single *sentinel* value, which is the destination value farthest from zero. For conversion to signed types, the sentinel is the minimum value for that type. Unsigned types use the maximum value. Floating-point operations may return a Not-a-Number (NaN) value to indicate an invalid operation. That's not an option for conversion to integer types, which don't have NaN values. The sentinel is used as a proxy for a NaN value, although it can also be the result of a valid conversion.
36
+
37
+
The **`/fpcvt:BC`** option also makes conversion to signed types return the minimum possible value when the source is invalid. However, conversion to unsigned integer types is based on conversion to **`long long`**. To convert a value to **`unsigned int`**, the compiler first converts it to type **`long long`**. The compiler then truncates the result to 32 bits. To convert a value to **`unsigned long long`**, valid source values that are too high for a **`long long`** are handled as a special case. All other values are first converted to **`long long`** and then recast to **`unsigned long long`**.
38
+
39
+
The **`/fpcvt`** options are new in Visual Studio 2019 version 16.8. If you specify more than one **`/fpcvt`** option on the command line, the later option takes precedence and the compiler generates a warning.
40
+
41
+
### Intrinsic functions for conversions
42
+
43
+
You can specify the behavior of a specific conversion independently of the **`/fpcvt `** option, which applies globally. The compiler provides intrinsic sentinel conversion functions for conversions compatible with **`/fpcvt:IA`**. For more information, see [Sentinel conversion functions](../../intrinsics/sentinel-conversion-functions.md). The compiler also provides saturation conversion functions compatible with conversions on ARM or ARM64 target architectures. For more information, see [Saturation conversion functions](../../intrinsics/saturation-conversion-functions.md).
44
+
45
+
The compiler also supports intrinsic conversion functions that execute as quickly as possible for valid conversions. These functions may generate any value or throw an exception for an invalid conversion. The results depend on the target platform, compiler options, and context. They're useful for handling values that have already been range-checked, or values generated in a way that can't cause an invalid conversion. For more information, see [Fast conversion functions](../../intrinsics/fast-conversion-functions.md).
46
+
47
+
### To set this compiler option in the Visual Studio development environment
48
+
49
+
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
0 commit comments