Chapter Contents |
Previous |
Next |

SAS Companion for the CMS Environment |

Representation of Floating-Point Numbers |

Under CMS, floating-point representation (unlike scientific notation) uses a base of 16 rather than base 10. IBM mainframe systems all use the same floating-point representation, which is made up of 4, 8, or 16 bytes. SAS always uses 8 bytes, as follows:

SEEEEEEE MMMMMMMM MMMMMMMM MMMMMMMM byte 1 byte 2 byte 3 byte 4 MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM byte 5 byte 6 byte 7 byte 8

This representation corresponds to bytes of data, with
each character occupying 1 bit. The S in byte 1 is the sign bit of the number.
If the sign bit is zero, the number is positive. Conversely, if the sign
bit is one, the number is negative. The seven E characters in byte 1 represent
a binary integer that is known as the **characteristic**. The characteristic
represents a signed exponent and is obtained by adding the bias to the actual
exponent. The bias is defined as an offset that is used to allow for both
negative and positive exponents, with the bias representing 0. If a bias
was not used, an additional sign bit for the exponent would have to be allocated.
For example, IBM mainframes employ a bias of 40 (base 16). A characteristic
with the value 42 represents an exponent of +2, whereas a characteristic of
3D represents an exponent of -3.

The remaining M characters in bytes 2 through 8 represent
the bits of the mantissa. There is an implied **radix point** before
the most significant bit of the mantissa, which also implies that the mantissa
is always strictly less than 1. The term radix point is used instead of decimal
point, because decimal point implies that we are working with decimal (base
10) numbers, which is not the case.

The exponent has a base associated with it. Do not confuse this with the base in which the exponent is represented. The exponent is always represented in binary, but the exponent is used to determine what power of the exponent's base should be multiplied by the mantissa. In the case of the IBM mainframes, the exponent's base is 16.

Each bit in the mantissa represents a fraction whose numerator is 1 and whose denominator is a power of 2. For example, the most significant bit in byte 2 represents 1/2 ** 1, the next most significant bit represents 1/2 ** 2, and so on. In other words, the mantissa is the sum of a series of fractions such as 1/2, 1/4, 1/8, and so on. Therefore, in order for any floating-point number to be represented exactly, you must be able to express it as the previously mentioned sum. For example, 100 is represented as the following expression:

(1/4 + 1/8 + 1/64) * (16 ** 2)

The following two examples illustrate how the preceding expression is obtained. The first example is in base 10. In decimal notation, the value 100 is represented as follows:

100.

The period in this number is the radix point. The mantissa must be less than 1; therefore, you normalize this value by shifting the number three places to the right, which produces the following value:

.100

Because the number was shifted three places to the right, 3 is the exponent, which results in the following expression:

.100*10**3=100

The second example is in base 16. In hexadecimal notation, 100 (base 10) is written as follows:

64.

The period in this number is the radix point. Shifting the number two places to the left produces the following value:

.64

Shifting the number two places also indicates an exponent of 2. Rewriting the number in binary produces the following value:

.01100100

Finally, the value .01100100 can be represented in the following expression:

In this example, the exponent is 2. To represent theexponent, you add the bias of 64 to the exponent. The hexadecimal representation of the resulting value, 66, is 42. The binary representation is as follows:

01000010 01100100 00000000 00000000 00000000 00000000 00000000 00000000

Floating-point numbers that have negative exponents
are represented with characteristics that are less than '40'x. When you subtract
'40'x from a number that is less than '40'x, the difference is a negative
value that represents the exponent. An example of such a number is the floating-point
representation of .03125_{10}, which is

'3F80000000000000'x

Subtracting '40'x from the characteristic, '3F'x, gives
an exponent of - 1_{16}. This exponent is applied
to the 14-digit fraction, '80000000000000'x, giving a value of .08_{16}, which is equal to .03125_{10}.

Representation of Integers |

You can use the IB**w.d** informat and format
to read and write these binary values. Each integer uses 4 bytes (32 bits)
of storage space; thus, the range of values that can be represented is -2,147,483,648
to 2,147,483,647.

Chapter Contents |
Previous |
Next |
Top of Page |

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.