Controls the semantics of floating-point calculations.
Windows: None
Linux: Floating Point > Floating Point Model
Mac OS: Floating Point > Floating Point Model
IA-32, IntelŪ EM64T, IntelŪ ItaniumŪ architecture
Linux and Mac OS: | -fp-model keyword |
Windows: | /fp:keyword |
keyword | Specifies the semantics to be used. Possible values are: | |
precise | Enables value-safe optimizations on floating-point data. | |
fast[=1|2] | Enables more aggressive optimizations on floating-point data. | |
strict | Enables precise and except, disables contractions, and enables pragma stdc fenv_access. | |
source | Rounds intermediate results to source-defined precision and enables value-safe optimizations. | |
double | Rounds intermediate results to 53-bit (double) precision and enables value-safe optimizations. | |
extended | Rounds intermediate results to 64-bit (extended) precision and enables value-safe optimizations. | |
[no-]except
(Linux and Mac OS) or except[-] (Windows) |
Determines whether floating-point exception semantics are used. |
-fp-model fast=1
or /fp:fast=1 |
The compiler uses more aggressive optimizations on floating-point calculations. However, if you specify -O0 (Linux and Mac OS) or /Od (Windows), the default is -mp (Linux and Mac OS) or /Op (Windows). |
This option controls the semantics of floating-point calculations.
The keywords can be considered in groups:
Group A: source, double, extended, precise, fast, strict
Group B: except (or the negative form)
You can use more than one keyword. However, the following rules apply:
You cannot specify fast and
except together in the same compilation. You can
specify any other combination of group A and group B.
Since fast is the default, you must not specify
except without a group A keyword.
You should specify only one keyword from group A. If you try to specify more than one keyword from group A, the last (rightmost) one takes effect.
If you specify except more than once, the last (rightmost) one takes effect.
Option | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-fp-model precise or /fp:precise | Tells the compiler to strictly adhere to value-safe optimizations when
implementing floating-point calculations. It disables optimizations that
can change the result of floating-point calculations, which is required
for strict ANSI conformance. These semantics ensure the accuracy of floating-point
computations, but they may slow performance. The compiler assumes the default floating-point environment; you are not allowed to modify it. Intermediate results are computed with the precision shown in the following table:
Floating-point exception semantics are disabled by default. To enable these semantics, you must also specify -fp-model except or /fp:except. For information on the semantics used to interpret floating-point calculations in the source code, see precise in Examples. | ||||||||||||||||
-fp-model fast[=1|2] or /fp:fast[=1|2] | Tells the compiler to use more aggressive optimizations when implementing
floating-point calculations. These optimizations increase speed, but may
alter the accuracy of floating-point computations. Specifying fast is the same as specifying fast=1. fast=2 may produce faster and less accurate results. Floating-point exception semantics are disabled by default and they cannot be enabled because you cannot specify fast and except together in the same compilation. To enable exception semantics, you must explicitly specify another keyword (see other keyword descriptions for details). For information on the semantics used to interpret floating-point calculations in the source code, see fast in Examples. | ||||||||||||||||
-fp-model strict or /fp:strict | Tells the compiler to strictly adhere to value-safe optimizations when
implementing floating-point calculations and enables floating-point exception
semantics. This is the strictest floating-point model. The compiler does not assume the default floating-point environment; you are allowed to modify it. Floating-point exception semantics can be disabled by explicitly specifying -fp-model no-except or /fp:except-. For information on the semantics used to interpret floating-point calculations in the source code, see strict in Examples. | ||||||||||||||||
-fp-model source or /fp:source | This option is similar
to keyword precise,
except intermediate results are rounded to the precision defined in the
source code. Intermediate expressions use the precision of the operand with higher precision, if any.
The compiler assumes the default floating-point environment; you are not allowed to modify it. For information on the semantics used to interpret floating-point calculations in the source code, see source in Examples. | ||||||||||||||||
-fp-model double or /fp:double | This option is similar to keyword
precise, except intermediate results are rounded
as follows:
The compiler assumes the default floating-point environment; you are not allowed to modify it. For information on the semantics used to interpret floating-point calculations in the source code, see double in Examples. | ||||||||||||||||
-fp-model extended or /fp:extended | This option is similar to keyword
precise, except intermediate results are rounded
as follows:
The compiler assumes the default floating-point environment; you are not allowed to modify it. For information on the semantics used to interpret floating-point calculations in the source code, see extended in Examples. | ||||||||||||||||
-fp-model except or /fp:except | Tells the compiler to use floating-point exception semantics. |
None
The included examples show:
Examples are provided for the following keywords:
Example source code:
float t0, t1, t2;
...
t0 = 4.0f + 0.1f + t1 + t2;
When this option is specified, the compiler applies the following semantics:
Additions may be performed in any order
Intermediate expressions may use single, double, or extended double precision
The constant addition may be pre-computed, assuming the default rounding mode
Using these semantics, the following shows some possible ways the compiler may interpret the original code:
float t0, t1, t2;
...
t0 = (float)((double)t1 + (double)t2) + 4.1f;
float t0, t1, t2;
...
t0 = (t1 + t2) + 4.1f;
float t0, t1, t2;
...
t0 = (t1 + 4.1f) + t2;
-fp-model
extended or /fp:extended
This setting is equivalent to -fp-model precise
on IA-32 Linux systems and fp-model precise or
/fp:precise on IntelŪ Itanium systems.
Example source code:
float t0, t1, t2;
...
t0 = 4.0f + 0.1f + t1 + t2;
When this option is specified, the compiler applies the following semantics:
Additions are performed in program order
Intermediate expressions use extended double precision
The constant addition may be pre-computed, assuming the default rounding mode
Using these semantics, the following shows a possible way the compiler may interpret the original code:
float t0, t1, t2;
...
t0 = (float)(((long double)4.1f + (long double)t1) + (long double)t2);
-fp-model source
or /fp:source
This setting is equivalent to -fp-model precise or /fp:precise
on IntelŪ EM64T systems.
Example source code:
float t0, t1, t2;
...
t0 = 4.0f + 0.1f + t1 + t2;
When this option is specified, the compiler applies the following semantics:
Additions are performed in program order, taking into account any parentheses
Intermediate expressions use the precision specified in the source code
The constant addition may be pre-computed, assuming the default rounding mode
Using these semantics, the following shows a possible way the compiler may interpret the original code:
float t0, t1, t2;
...
t0 = ((4.1f + t1) + t2);
-fp-model
double or /fp:double
This setting is equivalent to -fp-model precise
or /fp:precise on IA-32 Windows systems.
Example source code:
float t0, t1, t2;
...
t0 = 4.0f + 0.1f + t1 + t2;
When this option is specified, the compiler applies the following semantics:
Additions are performed in program order
Intermediate expressions use double precision
The constant addition may be pre-computed, assuming the default rounding mode
Using these semantics, the following shows s a possible way the compiler may interpret the original code:
float t0, t1, t2;
...
t0 = (float)(((double)4.1f + (double)t1) + (double)t2);
-fp-model strict or /fp:strict
Example source code:
float t0, t1, t2;
...
t0 = 4.0f + 0.1f + t1 + t2;
When this option is specified, the compiler applies the following semantics:
Additions are performed in program order, taking into account any parentheses
Expression evaluation matches expression evaluation under keyword precise
The constant addition will not be pre-computed, because there is no way to tell what rounding mode will be active when the program runs.
Using these semantics, the following shows a possible way the compiler may interpret the original code:
float t0, t1, t2;
...
t0 = (float)((((long double)4.0f + (long double)0.1f) +
(long
double)t1) + (long double)t2);
mp compiler option
Op compiler option
mp1, Qprec compiler option
The MSDN article Microsoft Visual C++ Floating-Point Optimization, which discusses concepts that apply to this option.