How to Design Programs: An Introduction to Programming and Computing

Info icon This preview shows pages 1–3. Sign up to view the full content.

How to Design Programs: An Introduction to Computing and Programming [Go to first , previous , next page; contents ; index ] Section 33 Intermezzo 6: The Nature of Inexact Numbers Computers represent and process information in chunks of a fixed size. Because computers were first used for numerical calculations, early computer engineers developed a representation for numbers in terms of fixed-size chunks. Programming languages must mediate the gap between these fixed-size representations and the true mathematics. Because using the hardware representation for numbers makes a program's calculations as efficient as possible, most designers and implementors of programming languages adopted the hardware-based choice. This intermezzo explains the fixed-size representation for numbers and its consequences in some detail. The first subsection introduces a concrete fixed-size representation for numbers, discusses what it implies for the representation of numbers, and shows how to calculate with such numbers. The second and third section illustrate the two most fundamental problems of fixed-size number arithmetic: overflow and underflow, respectively. 33.1 Fixed-size Number Arithmetic Suppose we can use four digits to represent numbers. If we represent natural numbers, the representable range is 0 ... 9999. Alternatively we could represent 10,000 fractions between 0 and 1 with that many digits. In either case, this is a rather small range of numbers and not useful for most scientific or business computations. We can represent a larger range of numbers if we use a different notation for numbers instead. In science, for example, we encounter so-called scientific notation, which represents numbers as two parts: 1. a MANTISSA , which is a base number, and 2. an EXPONENT , which is used to determine a 10-based factor. For pure scientific notation, the base is between 0 and 9. We relax this constraint and just write numbers as [curriculumE-Z-G-1.gif] where m is the mantissa and e the exponent. For example, one representation of 1200 with this scheme is (1 of 10) [2/5/2008 4:55:59 PM]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.