Floating Points Numbers and Round Off Error

What if you really want to know a decimal approximation to a quotient? The
simplest way is to end your numbers with decimal points. Mathematica will take the
hint and use decimal points when giving its answers. For example

6./21.

will give you the decimal approximation (to six places) that you might have
expected in the first place. Similarly,

2.^1000.

will give you a six-digit approximation expressed in scientific notation.

What's going on here? Why does Mathematica make such a big deal about expressing
answers exactly?

Mathematica is trying to avoid a common problem in computing: roundoff error. If
you've experimented very much with a pocket calculator, you've probably
discovered that operations that should be mathematical inverses often fail to
be. For example, the operation

10000000000000000. +1. - 10000000000000000.

should be exactly 1, but Mathematica prints out zero!! This is because Mathematica stores numbers with decimal points only to a certain accuracy, and one is so small compared to 10^17 that it ``disappears'' in round-off error. On the other hand,

10000000000000000  +1  - 10000000000000000 

gives an exact answer, because Mathematica represents the integers exactly.

Imagine that you are doing arithmetic by hand. If you restrict your
computations to integers and rational numbers (expressed as ratios of
integers), you can get an exact answer to any problem so long as you have
enough time and paper. The same applies to Mathematica, although it uses computer
memory instead of paper.

Of course, your computations will take a tremendous amount of time if you end
up dealing with 100-digit integers. You could save yourself a lot of time by
using decimal approximations to your fractions and by using scientific notation
to approximate your large integers. You would, of course, be giving up a
certain amount of accuracy in the process.

In effect, Mathematica gives you a choice. If you want answers that are correct to
the last digit, then stick to integers and ratios. If you are satisfied with
an answer that is correct to a fixed number of significant digits, then use
decimal points when writing your numbers. Numbers that are written with
decimal points are known in the computer world as floating-point numbers.
We'll use that term from here on out.

Evaluate each of the following floating point expressions and take a careful
look at the results.

1./9.

182347.1/234.4 

.08383/38383.2

What do all of the results have in common?

Click here for the answer