4.5 Floating-Point Numbers (float, double, long double)

When declaring floating-point variables, you determine the amount of precision needed for the stored object. In DEC C, you can have single-precision, double-precision, and extended double-precision variables.

The float keyword declares a single-precision, floating-point variable. A float variable is represented internally in the VAX compatible, F_floating-point binary format.

For double-precision variables, you can choose D_floating or G_ floating. On Alpha systems, you can also choose single- and double- precision IEEE formats (S_floating and T_floating, respectively), and extended double-precision format (X_floating).

The double keyword declares a double-precision, floating-point variable. DEC C provides two VAX C compatible formats for specifying double variables: D_floating or G_floating.

The G_floating precision of approximately 15 digits is less than that of variables represented in D_floating format. Although there are more bits allocated to the exponent in G_floating precision, fewer bits are allocated to the mantissa, which determines precision (see Table 4-3 ).


Note
When the compiler is run with the /STANDARD=VAXC qualifier, the use of the long float keyword, which is interchangeable with the double keyword, is allowed but elicits a warning that this is obsolete usage. The long float keyword is not allowed when the compiler is run with the /STANDARD=ANSI89 qualifier.

In VAX C, the default representation of double variables is D_ floating. To select the G_floating representation, you compiled with the /G_FLOAT qualifier.

In DEC C, the /FLOAT qualifier replaces the /G_FLOAT qualifier, but /G_FLOAT is retained for compatibility.

When compiling with DEC C on OpenVMS VAX systems, if you omit both /G_FLOAT and /FLOAT, the default representation of double variables is D_floating (unless /MIA is specified, in which case the default is G_floating).

When compiling with DEC C on OpenVMS Alpha systems, if you omit both /G_FLOAT and /FLOAT, the default representation of double variables is G_floating.

For OpenVMS Alpha systems, the /FLOAT qualifier accepts the additional option IEEE_FLOAT. If you specify /FLOAT=IEEE_FLOAT, single and double variables are represented in IEEE_floating format (S_floating for single float, and T_floating for double float).

You cannot specify both the /FLOAT and /G_FLOAT qualifiers on the command line.


Note
The VAX D_floating double-precision floating-point type is minimally supported on OpenVMS Alpha systems. When compiling with this type, all data transfer is done with the data in D_floating format, but for each arithmetic operation the data is converted first to G_floating and then back to D_floating format when the operation is complete. Therefore, it is possible to lose three binary digits of precision in arithmetic operations. This floating-point type is provided for compatibility with OpenVMS VAX systems.

Modules compiled with the D_floating representation should not be linked with modules compiled with the G_floating representation. Since there are no functions in the DEC C Run-Time Library (RTL) that perform floating-point format conversions on files, use the OpenVMS RTL functions MTH$CVT_D_G, MTH$CVT_G_D, MTH$CVT_DA_GA, and MTH$CVT_GA_DA if you do not wish to recompile the program. For more information about using the OpenVMS RTL, see the VMS Run-Time Library Routines Volume.

On OpenVMS VAX systems, DEC C maps the ANSI C defined long double type to the G_floating or D_floating format.

On OpenVMS Alpha systems, long double variables are represented by default in the software-emulated X_ floating format. If you specify /L_DOUBLE_SIZE=64, long double variables are represented as G_floating, D_floating, or T_floating, depending on the value of the /FLOAT or /G_FLOAT qualifier.


Note
Modules must be linked to the appropriate run-time library. For more information about linking against the DEC C RTL shareable image and object libraries, see the DEC C Run-Time Library Reference Manual for OpenVMS Systems.

Table 4-3 shows the supported floating-point formats, and their approximate sizes and range of values.

Table 4-3 Floating-Point Formats

Data type  Floating-Point Format  Length of Variable  Range of Values  Precision (decimal digits) 
float  F_floating  32-bit  2.9 * 1039 to 1.7 * 108  
double  D_floating  64-bit  2.9 * 10-39 to 1.7 * 108   16 
double  G_floating  64-bit  5.6 * 10-309 to 9.0 * 1007   15 
float  S_floating (Alpha only)  32-bit   1.2*10 -38 to 3.4*10 38  
double  T_floating (Alpha only)  64-bit   2.2*10-308 to 1.8*10 308   15 
long double  X_floating (Alpha only)   128-bit  3.4*10 -4932 to 1.2*10 4932   33 


Previous Page | Next Page | Table of Contents | Index