2.2.1.2 Real Constants

A real constant is a number written with a decimal point, exponent, or both. The constant can be positive, zero, or negative. It can have single precision (REAL*4), double precision (REAL*8), or quad precision (REAL*16).

REAL (REAL*4) Constants

A REAL constant can be any one of the following:

A basic real constant takes one of the following forms:

   s.nn
 snn.nn
 snn.
s
Is an optional sign.
nn
Is a string of decimal digits. One decimal point can appear anywhere in the string.

A single-precision decimal exponent is denoted by the letter E and takes the following form:

Esnn
s
Is an optional sign.
nn
Is a string of decimal digits.

Rules and Behavior

A REAL constant occupies four bytes of memory. It is interpreted as a real number with a degree of precision that is typically seven decimal digits.

The number of digits is not limited, but typically only the leftmost seven digits are significant. Leading zeros (zeros to the left of the first nonzero digit) are ignored in counting the leftmost seven digits. Therefore, in the constant 0.00001234567, all of the nonzero digits, and none of the zeros, are significant.

The exponent represents a power of 10 by which the preceding real or integer constant is to be multiplied (for example, 1.0E6 represents the value 1.0 * 10**6).

A minus sign must appear before a negative REAL constant; a plus sign is optional before a positive constant. Similarly, a minus sign must appear between the letter E and a negative exponent, whereas a plus sign is optional between the letter E and a positive exponent.

A REAL constant contains the numerals 0 through 9, algebraic signs, a decimal point, and the letter E followed by an integer constant exponent field. The exponent field cannot be omitted, but it can be zero.

The ranges for the REAL*4 data type formats are shown in Section E.3.

Examples

The following examples show valid and invalid REAL constants:

Valid   
3.14159    
621712.    
-.00127    
+5.0E3    
2E-3    
Invalid  Explanation 
1,234,567.   Commas not allowed 
325E-47   Too small 
-47.E47   Too large 
100   Decimal point missing; this is a valid integer constant 
$25.00   Special character not allowed 

For More Information:

For details on the format of REAL (REAL*4) data, see your user manual.


DOUBLE PRECISION (REAL*8) Constants

A DOUBLE PRECISION constant is a basic real constant or an integer constant followed by a decimal exponent. A double-precision decimal exponent is denoted by the letter D and takes the following form:

Dsnnn
s
Is an optional sign.
nnn
Is a string of decimal digits.

Rules and Behavior

A DOUBLE PRECISION constant occupies eight bytes of memory. The number of digits that precede the exponent is unlimited.

A minus sign must appear before a negative DOUBLE PRECISION constant; a plus sign is optional before a positive constant. Similarly, a minus sign must appear between the letter D and a negative exponent, whereas a plus sign is optional between the letter D and a positive exponent.

A DOUBLE PRECISION constant contains the numerals 0 through 9, algebraic signs, a decimal point, and the letter D followed by an integer constant exponent field. The exponent field cannot be omitted, but it can be zero.

Implementations of DOUBLE PRECISION (REAL*8)

The DOUBLE PRECISION formats are implemented as follows:

The ranges for the REAL*8 data type formats are shown in Section E.3.

On Alpha processors, you can use the syntax Qsnnn if the exponent field is within the double precision range.

Examples

The following examples show valid and invalid DOUBLE PRECISION constants:

D_floating DOUBLE PRECISION Constants (VMS only) 
Valid   
1234567890D+5    
+2.71828182846182D00    
-72.5D-15    
1D0    
Invalid  Explanation 
1234567890D45   Too large 
1234567890.0D-89   Too small 
+2.7182812846182   No D exponent designator is present; this is a valid single-precision constant 
G_floating DOUBLE PRECISION Constants (VMS only) 
Valid   
123456789.D0    
+2.34567890123D-5    
-1D+300    
Invalid  Explanation 
123456789.D400   Too large 
123456789.D-400   Too small 
T_floating DOUBLE PRECISION Constants (Alpha only) 
Valid   
123456789D+5    
+2.7843D00    
-.52.2D-12    
2D200    
Invalid  Explanation 
6.213D   Integer constant exponent field is missing after the D 
-3.7651   D exponent designator is missing. This is a valid single-precision constant 

For More Information:

For details on the format of DOUBLE PRECISION (REAL*8) data, see your user manual.


REAL*16 Constants

A REAL*16 constant is a basic real constant or an integer constant followed by a decimal exponent. A quad-precision decimal exponent is denoted by the letter Q and takes the following form:

Qsnnn
s
Is an optional sign.
nnn
Is a string of decimal digits.

Rules and Behavior

A REAL*16 constant occupies 16 bytes of memory. The number of digits that precede the exponent is unlimited; however, typically only the leftmost 33 digits are significant.

A minus sign must appear before a negative REAL*16 constant, but a plus sign is optional before a positive constant. Similarly, a minus sign is required between the letter Q and a negative exponent, but a plus sign is optional between the letter Q and a positive exponent.

A REAL*16 constant contains the numerals 0 through 9, algebraic signs, a decimal point, and the letter Q followed by an integer constant exponent field.

The exponent field cannot be omitted, but it can be zero.

On VAX processors, H_floating format is used to implement REAL*16. On Alpha processors, IEEE X_floating format is used to implement REAL*16.

The ranges for the REAL*16 data type formats are shown in Section E.3.

Some processors emulate floating-point data types rather than executing them in hardware or microcoded instruction. Processing time with software emulation is much slower. You should be aware of which data types are emulated on your system and choose the type with this information in mind.

Examples

The following examples show valid and invalid REAL*16 constants:

Valid   
123456789Q4000    
-1.23Q-400    
+2.72Q0    
Invalid  Explanation 
1.Q5000   Too large 
1.Q-5000   Too small 

For More Information:

For details on the format of REAL*16 data, see your user manual.


Previous Page Next Page Table of Contents