/FP Options (Select Floating-Point-Math Package)

The /FPa, /FPc, /FPc87, /FPi, and /FPi87 options specify how your program handles floating-point-math operations. The following table summarizes the different options:

Table 13.4 Floating-Point Options


Generated
Code
Default
Library
Link-Time Possibilities
Comments

/FPa Function calls to mLIBCA.LIB mLIBCA.LIB mLIBCE.LIB mLIBC7.LIB (4, 5)
/FPc Function calls to mLIBCE.LIB mLIBCE.LIB mLIBCA.LIB mLIBC7.LIB (5)
/FPc87 Function calls to mLIBC7.LIB mmIBC7.LIB mLIBCA.LIB mLIBCE.LIB (1, 5)
/FPi Software interrupts mLIBCE.LIB mLIBCE.LIB mLIBC7.LIB, (2)  
/FPi87 Inline 80x87 instructions mLIBC7.LIB mLIBCE.LIB, (1, 3)  

1 Requires a math coprocessor if program is linked with mLIBC7.LIB.

2 The executable file interacts with the NO87 environment variable allowing run-time selection of using either the emulator library or a math coprocessor.

3 Produces the smallest, fastest code if a coprocessor is available.

4 Produces the fastest code if no coprocessor is available.

5 Libraries that are compiled with this option can later be linked with any Microsoft floating-point library.

/FPa (Alternate Math Package)

This option generates floating-point calls and selects the alternate math library for the current memory model (mLIBCA.LIB). Calls to this library provide the fastest and smallest code if you do not have an 80x87 coprocessor. This library provides full IEEE 64-bit precision using doubles and 32-bit precision using floats. Long doubles are not supported.

At link time, you can specify an emulator library (mLIBCE.LIB) or an 80x87
library (mLIBC7.LIB). These libraries provide 80-bit precision.

Note that neither the Fast Compile option (/f) nor the p-code option (/Oq) support the /FPa option.

/FPc (Coprocessor)

The /FPc option generates floating-point calls to the emulator library and places the name of an emulator library (mLIBCE.LIB) in the object file.

At link time, you can specify an 80x87 library (mLIBC7.LIB) or alternate math library (mLIBCA.LIB) instead. The /FPc option gives you flexibility in your choice of libraries for linking.

This option is recommended if you compile modules that:

Perform floating-point operations (when you plan to include these modules in a library).

Link with libraries other than the libraries provided with this compiler.

Note that certain optimizations are not performed when /FPc is used. This may reduce the efficiency of your code. The /FPc option is not supported with either the Fast Compile option (/f) or the p-code option (/Oq).

/FPc87 (80x87 Calls)

This option generates function calls to routines in the 80x87 library (mLIBC7.LIB) in order to perform the corresponding 80x87 instructions.

You must have an 80x87 coprocessor installed to run programs compiled with the /FPc87 option and linked with an 80x87 library. Otherwise, the program fails and an error message is displayed.

If an 80x87 coprocessor is unavailable, you can specify an emulator library (mLIBCE.LIB) or the appropriate alternate math library (mLIBCA.LIB) at link time.

Note that certain optimizations are not performed when /FPc87 is used. This may reduce the efficiency of your code. The /FPc87 option is not supported with either the Fast Compile option (/f) or the p-code option (/Oq).

/FPi (Emulator)

Use the /FPi option if you do not know whether a math coprocessor will be available at run time. Programs compiled with /FPi work as follows:

If a coprocessor is present at run time, the program uses the coprocessor.

If no coprocessor is present or if the NO87 environment variable has been set, the program uses the emulator.

The /FPi option generates inline instructions for an 80x87 coprocessor and places the name of the emulator library (mLIBCE.LIB) in the object file. At link time, you can specify an 80x87 library (mLIBC7.LIB) instead. If you do not choose a floating-point option, CL uses the /FPi option by default.

This option works whether or not a coprocessor is present because the compiler does not generate “true” inline 80x87 instructions. Instead, it generates software interrupts to library code. The library code, in turn, adds fixups to the interrupts to select either the emulator or the coprocessor, depending on whether a coprocessor is present.

/FPi87 (Coprocessor)

The /FPi87 option includes the name of an 80x87 library (mLIBC7.LIB) in the object file. At link time, you can override this option and specify an emulator library (mLIBCE.LIB) instead so that the program runs on computers without coprocessors.

If you use the /FPi87 option and link with mLIBC7.LIB, an 8087 or 80287 coprocessor must be present at run time; otherwise, the program fails and the following error message is displayed:

run-time error R6002

- floating point not loaded

If you compile with /FPi87 and link with mLIBCE.LIB, you can set the NO87 environment variable to suppress the use of the coprocessor.

Compiling with the /FPi87 option results in the smallest, fastest programs possible for handling floating-point arithmetic.

Library Considerations for Floating-Point Options

You may want to use libraries in addition to the default library for the floating-point option you have chosen on the CL command line. For example, you may want to create your own libraries or object files, then link them at a later time with object files that you have compiled using different CL options.

You must be sure that you use only one standard combined C library when you link. You can control which library the linker uses in one of two ways:

Make sure the first object file passed to the linker has the name of the desired library. For example, if you want to use an 80x87 library, give the /FPi87 option before the first source-file name on the CL command line. You can also give the name of an object file compiled with /FPi87 as the first filename on the command line. All floating-point calls in this object file refer to the 80x87 library.

Give the /NOD (no default-library search) option after the /link option on the CL command line. Then specify the name of the library you want to use on the CL command line. The /NOD option overrides the library names embedded in the object files. Because the linker searches libraries given on the command line before it searches libraries named in object files, all floating-point calls refer to the libraries you specify.

Another complication might arise if you create your own libraries: usually, each module in the library you create contains a standard-library name, and the linker tries to search the standard libraries named in the modules when it links with your library.

The safest course, especially when you are distributing libraries to others, is to use the /Zl option when you compile the object files that make up your libraries. The /Zl option tells the compiler not to put library names in the object files. Later, when you link other object files with your library, the standard library used for linking depends only on the floating-point and memory-model options used to compile those object files.

Examples

CL CALC.C ANOTHER SUM

In this example, no floating-point option is given, so CL compiles the source file CALC.C with the default floating-point option, /FPi. The /FPi option generates inline instructions and selects the small-model-emulator combined library (SLIBCE.LIB), which is the default.

CL /FPi87 CALC.C ANOTHER.OBJ SUM.OBJ SLIBCE.LIB /link /NOD

In this example, CL compiles CALC.C with the /FPi87 option, which selects the SLIBC7.LIB library. The /link option, however, overrides the default library specification: the /NOD option suppresses the search for the default library, and the emulator library (SLIBCE.LIB) is specified. LINK uses SLIBCE.LIB when it creates the resulting executable file, CALC.EXE.

Compatibility Between Floating-Point Options

Each time you compile a source file, you can specify a floating-point option. When you link two or more source files to produce an executable program file, you are responsible for ensuring that floating-point operations are handled in a consistent way.

Example

CL /AM CALC.C ANOTHER SUM /link MLIBC7.LIB /NOD

This example compiles the program CALC.C with the medium-model option (/AM). Because no floating-point option is specified, the default (/FPi) is used. The /FPi option generates inline 80x87 instructions and specifies the emulator library MLIBCE.LIB in the object file. The /link field specifies the /NOD option and the name of the medium-model 80x87 library, MLIBC7.LIB. Specifying the 80x87 library forces the program to use an 8087 coprocessor; the program fails if a coprocessor is not present.

The NO87 Environment Variable

Programs compiled with the /FPi option automatically use an 80x87 coprocessor at run time if one is installed. You can override this and force the use of the emulator instead by setting an environment variable named NO87.

If NO87 is set to any value when the program is executed, the program uses the emulator even if a coprocessor is present. When this occurs, the NO87 setting is displayed on the standard output device as a message. The message is displayed only if a coprocessor is present and its use is suppressed; if no coprocessor is present, no message appears. If you want to force use of the emulator but don't want a message to appear, set NO87 equal to one or more spaces. The variable is still considered to be defined.

Note that the presence or absence of the NO87 definition determines whether use of the coprocessor is suppressed. The actual value of the NO87 setting is used only for the message.

The NO87 variable takes effect with any program linked with an emulator library (mLIBCE.LIB). It has no effect on programs linked with 8087/80287 libraries (mLIBC7.LIB).

Examples

SET NO87=Use of coprocessor suppressed

This example causes the message Use of coprocessor suppressed to appear when a program that would use an 80x87 coprocessor is executed on a computer that has such a coprocessor.

SET NO87=space

This example sets the NO87 variable to the space character. Use of the coprocessor is still suppressed, but no message is displayed.

Standard Combined Libraries

Table 13.5 shows each combination of memory-model and floating-point options and the corresponding library name that CL embeds in the object file.

Table 13.5 CL Options and Default Libraries

Floating-Point Option Memory-Model Option Default Library

/FPi87 /AT or /AS SLIBC7.LIB
  /AM MLIBC7.LIB
  /AC CLIBC7.LIB
  /AL or /AH LLIBC7.LIB
/FPi /AT or /AS SLIBCE.LIB
  /AM MLIBCE.LIB
  /AC CLIBCE.LIB
  /AL or /AH LLIBCE.LIB