FORTRAN 77 Language Reference

# Appendix C Data Representations

Whatever the size of the data element in question, the most significant bit of the data element is always stored in the lowest-numbered byte of the byte sequence required to represent that object.

This appendix is a brief introduction to data representation. For more in-depth explanations, see the Sun Fortran Programming Guide and Numerical Computation Guide.

# Real, Double, and Quadruple Precision

Real, double precision, and quadruple precision number data elements are represented according to the IEEE standard by the following form, where f is the bits in the fraction. Quad is SPARC only.

(-1)sign * 2exponent-bias *1.f

Table C-1 Floating-point Representation

Single

Double

Sign

Bit 31

Bit 63

Bit 127

Exponent

Bits 30-23 Bias 127

Bits 62-52 Bias 1023

Bits 126-112 Bias 16583

Fraction

Bits 22-0

Bits 51-0

Bits 111-0

Range approx.

3.402823e+38 1.175494e-38

1.797693e+308 2.225074e-308

3.362E-4932 1.20E+4932

# Extreme Exponents

The representations of extreme exponents are as follows.

## Zero (signed)

Zero (signed) is represented by an exponent of zero and a fraction of zero.

## Subnormal Number

The form of a subnormal number is:

(-1) sign * 2 1-bias *0.f

where f is the bits in the significand.

## Signed Infinity

Signed infinity--that is, affine infinity--is represented by the largest value that the exponent can assume (all ones), and a zero fraction.

## Not a Number (NaN)

Not a Number (NaN) is represented by the largest value that the exponent can assume (all ones), and a nonzero fraction.

Normalized REAL and DOUBLE PRECISION numbers have an implicit leading bit that provides one more bit of precision than is stored in memory. For example, IEEE double precision provides 53 bits of precision: 52 bits stored in the fraction, plus the implicit leading 1.

# IEEE Representation of Selected Numbers

The values here are as shown by dbx, in hexadecimal.

Table C-2 IEEE Representation of Selected Numbers

Value

Single-Precision

Double-Precision

+0

00000000

0000000000000000

-0

80000000

8000000000000000

+1.0

3F800000

3FF0000000000000

-1.0

BF800000

BFF0000000000000

+2.0

40000000

4000000000000000

+3.0

40400000

4008000000000000

+Infinity

7F800000

7FF0000000000000

-Infinity

FF800000

FFF0000000000000

NaN

7Fxxxxxx

7FFxxxxxxxxxxxxx

# Arithmetic Operations on Extreme Values

This section describes the results of basic arithmetic operations with extreme and ordinary values. We assume all inputs are positive, and no traps, overflow, underflow, or other exceptions happen.

Table C-3 Extreme Value Abbreviations

Abbreviation

Meaning

Sub

Subnormal number

Num

Normalized number

Inf

Infinity (positive or negative)

NaN

Not a Number

Uno

Unordered

Table C-4 Extreme Values: Addition and Subtraction

Left Operand

Right Operand

Sub

Num

Inf

NaN

Sub

Num

Inf

NaN

Sub

Sub

Sub

Num

Inf

NaN

Num

Num

Num

Num

Inf

NaN

Inf

Inf

Inf

Inf

Note

NaN

NaN

NaN

NaN

NaN

NaN

NaN

Note: Inf Inf and Inf + Inf = Inf ; Inf - Inf = NaN.

Table C-5 Extreme Values: Multiplication

Left Operand

Right Operand

Sub

Num

Inf

NaN

NaN

NaN

Sub

NS

Inf

NaN

Num

NS

Num

Inf

NaN

Inf

NaN

Inf

Inf

Inf

NaN

NaN

NaN

NaN

NaN

NaN

NaN

In the above table, NS means either Num or Sub result possible.

Table C-6 Extreme Values: Division

Left Operand

Right Operand

Sub

Num

Inf

NaN

NaN

NaN

Sub

Inf

Num

Num

NaN

Num

Inf

Num

Num

NaN

Inf

Inf

Inf

Inf

NaN

NaN

NaN

NaN

NaN

NaN

NaN

NaN

Table C-7 Extreme Values: Comparison

Left Operand

Right Operand

Sub

Num

Inf

NaN

Uno

Sub

Uno

Num

Uno

Inf

Uno

NaN

Uno

Uno

Uno

Uno

Uno

Notes:

• If either X or Y is NaN, then X.NE.Y is .TRUE., and the others (.EQ., .GT., .GE., .LT., .LE.) are .FALSE.

• +0 compares equal to -0.

• If any argument is NaN, then the results of MAX or MIN are undefined.

# Bits and Bytes by Architecture

The order in which the data--the bits and bytes--are arranged differs between VAX computers on the one hand, and SPARC computers on the other.

The bytes in a 32-bit integer, when read from address n, end up in the register as shown in the following tables.

Table C-8 Bits and Bytes for Intel and VAX Computers

Byte n+3

Byte n+2

Byte n+1

Byte n

31 30 29 28 27 26 25 24   23 22 21 20 19 18 17 16   15 14 13 12 11 10 09 08   07 06 05 04 03 02 01 00
Most Significant     Least significant

Table C-9 Bits and Bytes for 680x0 and SPARC Computers

Byte n

Byte n+1

Byte n+2

Byte n+3

31 30 29 28 27 26 25 24  23 22 21 20 19 18 17 16  15 14 13 12 11 10 09 08  07 06 05 04 03 02 01 00
Most Significant     Least significant

The bits are numbered the same on these systems, even though the bytes are numbered differently.

Following are some possible problem areas:

• Passing binary data over the network. Use External Data Representation (XDR) format or another standard network format to avoid problems.

• Porting raster graphics images between architectures. If your program uses graphics images in binary form, and they have byte ordering that is not the same as for images produced by SPARC system routines, you must convert them.

• If you convert character-to-integer or integer-to-character between architectures, you should use XDR.

• If you read binary data created on an architecture with a different byte order, then you must filter it to correct the byte order.