1 is equal to 2 for sufficiently large values of 1.

—Anonymous

Computers handle integers very well. The arithmetic is simple, exact, and fast. Floating-point arithmetic is the opposite. Computers do floating-point arithmetic only with great difficulty.

This chapter discusses some of the problems that can occur with floating-point. In order to understand the principles involved in floating-point arithmetic, we have defined a simple decimal floating-point format. We suggest you put aside your computer and work through these problems using pencil and paper so that you can see firsthand the problems and pitfalls that occur.

The format used by computers is very similar to the one defined in this chapter, except that instead of using base 10, computers use base 2, 8, or 16. However, all the problems demonstrated here on paper can occur in a computer.

Floating-point numbers consist of three parts: a sign, a fraction, and an exponent. Our fraction is expressed as a 4-digit decimal. The exponent is a single-decimal digit. So, our format is:

where:

- ±
is the sign (plus or minus).

- f.fff
is the 4 digit fraction.

- ±e
is the single-digit exponent with sign.

Zero is +0.000 x 10 ^{+0}. We represent
these numbers in “E” format: ±*0.000* `E`

±e.

This format is similar to the floating-point format used in many computers. The IEEE has defined a floating-point standard (#754), ...

Start Free Trial

No credit card required