fp-model, fp

Controls the semantics of floating-point calculations.

IDE Equivalent

Windows: Code Generation>Floating Point Model

Code Generation>Enable Floating Point Exceptions

Code Generation> Floating Point Expression Evaluation

Linux: Floating Point > Floating Point Model

Mac OS X: Floating Point > Floating Point Model

Floating Point > Reliable Floating Point Exceptions Model

Architectures

IA-32, Intel® 64, IA-64 architectures

Syntax

Linux and Mac OS X:

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

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.

extended

Rounds intermediate results to 64-bit (extended) precision.

[no-]except (Linux and Mac OS X) 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.

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.

Intermediate results are computed with the precision shown in the following table, unless it is overridden by a keyword from Group B:

Windows

Linux

Mac OS X

IA-32 architecture

Double

Extended

Extended

Intel® 64 architecture

Source

Source

Source

IA-64 architecture

Extended

Extended

N/A

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 Floating-point Operations: Using the -fp-model (/fp) Option.

-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 Floating-point Operations: Using the -fp-model (/fp) Option.

-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 Floating-point Operations: Using the -fp-model (/fp) Option.

-fp-model source or /fp:source

This option causes intermediate results to be rounded to the precision defined in the source code. It also implies keyword precise unless it is overridden by a keyword from Group A.

Intermediate expressions use the precision of the operand with higher precision, if any.

long double

64-bit precision

80-bit data type

15-bit exponent

double

53-bit precision

64-bit data type

11-bit exponent; on Windows systems using IA-32 architecture, the exponent may be 15-bit if an x87 register is used to hold the value.

float

24-bit precision

32-bit data type

8-bit exponent

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 Floating-point Operations: Using the -fp-model (/fp) Option.

-fp-model double or /fp:double

This option causes intermediate results to be rounded as follows:

53-bit (double) precision

64-bit data type

11-bit exponent; on Windows systems using IA-32 architecture, the exponent may be 15-bit if an x87 register is used to hold the value.

This option also implies keyword precise unless it is overridden by a keyword from Group A.

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 Floating-point Operations: Using the -fp-model (/fp) Option.

-fp-model extended or /fp:extended

This option causes intermediate results to be rounded as follows:

64-bit (extended) precision

80-bit data type

15-bit exponent

This option also implies keyword precise unless it is overridden by a keyword from Group A.

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 Floating-point Operations: Using the -fp-model (/fp) Option.

-fp-model except or /fp:except

Tells the compiler to use floating-point exception semantics.

Note iconNote

On Windows and Linux operating systems on IA-32 architecture, the compiler, by default, implements floating-point (FP) arithmetic using SSE2 and SSE instructions. This can cause differences in floating-point results when compared to previous x87 implementations.

Alternate Options

None

Example

For examples of how to use this option, see Floating-point Operations: Using the -fp-model (/fp) Option.

See Also