fp-model, fp

Controls the semantics of floating-point calculations.

IDE Equivalent

None

Architectures

IA-32, IntelŪ EM64T, IntelŪ ItaniumŪ architecture

Syntax

Linux and Mac OS: -fp-model keyword
Windows:  /fp:keyword

Arguments

keyword Specifies the semantics to be used. Possible values are:
  precise Enables value-safe optimizations on floating-point data and rounds intermediate results to source-defined precision.
  fast[=1|2] Enables more aggressive optimizations on floating-point data.
  strict Enables precise and except, disables contractions, enables the property that allows modification of the floating-point environment.
  source Enables value-safe optimizations on floating-point data and rounds intermediate results to source-defined precision.
  [no-]except (Linux and Mac OS) or
except[-]
(Windows)
Determines whether floating-point exception semantics are used.

Default

-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 fltconsistency.

Description

This option controls the semantics of floating-point calculations.

The keywords can be considered in groups:

You can use more than one keyword. However, the following rules apply:

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.
 
Floating-point exception semantics are disabled by default. To enable these semantics, you must also specify -fp-model except or /fp:except.

This keyword is equivalent to keyword
source.

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 equivalent to keyword precise. In both cases, intermediate results are rounded to the precision defined in the source code and only value-safe optimizations are used for floating-point calculations. (For more details, see the description of precise above.) 
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 except or /fp:except Tells the compiler to use floating-point exception semantics.

Note

This option cannot be used to change the default (source) precision for the calculation of intermediate results.

Alternate Options

None

Examples

The included examples show:

Examples are provided for the following keywords:

-fp-model fast or /fp:fast

Example source code:

REAL T0, T1, T2;
...
T0 = 4.0E + 0.1E + T1 + T2;

When this option is specified, the compiler applies the following semantics:

Using these semantics, the following shows some possible ways the compiler may interpret the original code:

REAL T0, T1, T2;
...
T0 = (T1 + T2) + 4.1E;

 

REAL T0, T1, T2;
...
T0 = (T1 + 4.1E) + T2;

 

-fp-model source or /fp:source
This setting is equivalent to -fp-model precise or /fp:precise.

Example source code:

REAL T0, T1, T2;
...
T0 = 4.0E + 0.1E + T1 + T2;

When this option is specified, the compiler applies the following semantics:

Using these semantics, the following shows a possible way the compiler may interpret the original code:

REAL T0, T1, T2;
...
T0 = ((4.1E + T1) + T2);

 

-fp-model strict or /fp:strict

Example source code:

REAL T0, T1, T2;
...
T0 = 4.0E + 0.1E + T1 + T2;

When this option is specified, the compiler applies the following semantics:

Using these semantics, the following shows a possible way the compiler may interpret the original code:

REAL T0, T1, T2;
...
T0 = REAL ((((REAL)4.0E + (REAL)0.1E) + (REAL)T1) + (REAL)T2);

See Also

fltconsistency compiler option

mp1, Qprec compiler option

The MSDN article Microsoft Visual C++ Floating-Point Optimization, which discusses concepts that apply to this option.

Building Applications: Native IEEE* Floating-Point Representations Overview

Optimizing Applications: Floating-point Arithmetic Optimizations Overview