Maple provides two kinds of numbers: exact and inexact. If you do
arithmetic with exact numbers (and they aren't too large) the answer that you
get back is exactly right. If you do arithmetic with inexact numbers (and they
aren't too large or too small) the answer may have a small amount of roundoff
error. Although we'll treat this distinction at length in future lessons, it
is convenient to take a preliminary look right now.
In Maple, rational numbers (integers and fractions) are exact. If you do
arithmetic with rational numbers, your answer will be correct to the last
digit. Here are some examples.
- We divide two integers, and end up with an exact fraction, expressed in
lowest terms:
 | 2468/1324; |
- We add two fractions, and end up with another fraction containing a lot
of digits:
 | 23848/837443 + 87533/9283932; |
- We do exponentiation and wind up with an astonishing number of digits:
 | 444^555; |
Maple also provides inexact floating-point numbers. Maple floating-point
numbers look different from integers because they either contain a decimal
point or are written using scientific notation. If you do arithmetic with
floating-point numbers, your answer will be rounded off to ten digits. We will
repeat the same three examples from above, using floating-point numbers instead
of integers.
- We add two floating-point numbers (note the decimal points), and wind up
with a decimal approximation to the exact answer:
 | 2468./1324.; |
- We add two ratios of floating-point numbers, and wind up with a
floating-point answer. Note that we have written the numbers in scientific
notation. The portion before the ``e'' is the mantissa, and the portion
following the ``e'' is the exponent:
 | 2.3848e4 / 8.37443e5 + 8.7533e4 / 9.283932e6; |
- We do an exponentiation. Even though one of the operands is an integer
and the other is a floating-point number, the answer is a floating-point
number. When even one inexact number is used in a computation, the result is
always inexact:
 | 444.^555; |
Notice that each of the last three answers contains a ten-digit mantissa
scaled, if necessary, by a power of ten.
Why, if Maple can do exact arithmetic to the very last digit, do we need to
bother with floating-point numbers? Can you think of some reasons why?
Click here for the answer
Joseph L. Zachary
Hamlet Project
Department of Computer Science
University of Utah