Programming and Graphics

(Kiana) #1

1.6 Floating-point representation 19


1.6 Floating-point representation


The floating-point representation allows us to store real numbers (non-integers)
with a broad range of magnitudes, and carry out mathematical operations be-
tween numbers with disparate magnitudes.


Consider the binary number:

1001100101. 01100011101

To develop the floating-point representation, we recast this number into the
product:


1. 00110010101100011101 × 1000000000 (34)

Note that the binary point has been shifted to the left by nine places, and
the resulting number has been multiplied by the binary equivalent of 2^9 .The
binary string 100110010101100011101 is themantissaorsignificand, and 9 is
theexponent.


To develop the floating-point representation of an arbitrary number, we
express it in the form:
±s 2 e


wheresis a real number called themantissaorsignificand,andeis the integer
exponent. This representation requires one bit for the sign, a set of bytes for
the exponent, and another set of bytes for the mantissa. In memory, the bits
are arranged sequentially in the following order:


signexponent mantissa

The exponent determines the shift of the binary point in the binary represen-
tation of the mantissa.


Many combinations ofsandegenerate the same number. The normalized
representation leaves as many zeros as possible at the end of the binary string.
This means that the first digit of the mantissa is always non-zero and thus equal
to one. We can exploit this convention to avoid storing this bit and thus gain
one binary digit of accuracy. We then say that the mantissa has one “hidden
bit.” The exponent is stored after it has been shifted by an integer bias so as
to become positive. This shift saves us from allocating one bit to the exponent
sign.


How can we store the number zero? By convention, if all bits of the
floating point string after the sign are zero, the hidden bit is also zero, yielding
the number zero. Infinity is encoded by a floating point string with all ones for
the bits of the exponent, and all zeros for the bits of the mantissa.

Free download pdf