Decimal Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm Harder. All rights reserved. ECE 204 Numerical Methods for Computer Engineers
Decimal Numbers This topic is a quick review of decimal numbers, both integers and real numbers –standard notation –scientific notation –addition –multiplication
Decimal Numbers We represent an integer as a sequence of decimal digits: d n d n – 1 d n – 2 · · · d 2 d 1 d 0 where d n 0 This represents the number
Decimal Numbers For example, represents or 2· · · · · ·10 0
Decimal Numbers The sequence of integers is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,..., 17, 18, 19, 20, 21,... where we increment the next decimal digit to the left whenever we add one to a 9 Note that there is nothing special about “ten”, the base of our number system Our decimal system uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Decimal Numbers We represent a real number as a sequence of decimal digits: d n d n – 1 · · · d 1 d 0. d –1 d –2 d –3 · · · where d n 0, and n is any integer This represents the number
Decimal Numbers For example, = ··· represents ··· or 3· ·10 –1 + 4·10 –2 + 1·10 –3 + 4·10 –4 + 9·10 –5 + ···
Decimal Numbers We cannot store an infinite number of decimal digits, and therefore, we approximate real numbers using a finite number of decimal digits: d n d n – 1 · · · d 0. d –1 · · · d m where d n 0, n is any integer and m n This represents the number
Decimal Numbers For example, represents or 2· · · ·10 –1 + 3·10 –1 + 2·10 –2 Also, 3.14 represents = 3· ·10 –1 + 4·10 –2
Decimal Numbers These formats can be inconvenient if n and m are either both very large or both very small: and thus it is common to use scientific notation to represent real numbers or their approximations
Decimal Numbers Any real number can be written as d 0.d -1 d -2 d -3 · · · d –m 10 n where d 0 0 This is often more conveniently written as d 0.d -1 d -2 d -3 ···d –m en where n is the exponent, e denotes exponent, and the digits d 0.d -1 d -2 d -3 ···d are the mantissa
Decimal Numbers For example: – may be written as 10 2 or e2 –3.14 may be written as 3.14 10 0 or 3.14e0 – may be written as or 5.232e13 – may be written as 10 –14 or 5.232e-14
Decimal Numbers To add two decimal numbers: –line up the decimal points, add the columns, carrying 1 to next column if the sum is greater than 9 : –for example, add = e3 and = e0 yielding e3
Decimal Numbers Multiplication of numbers in scientific notation is similar, multiply the mantissa and add the exponents –for example, multiply = 2.7e4 and 0.32 = 3.2e-1 yielding 8.64e3 where 3 = 4 + –1
Decimal Numbers In both addition and multiplication, an adjustment may have to be made to keep the numbers in scientific notation For example, 9.25e e0 = 14.48e0 = 1.448e1
Decimal Numbers The justification for these apparently obvious examples is that we will next be working with binary numbers –computers can only store binary numbers –the representation is slightly different, but the operations are the same
Usage Notes These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: –that you inform me that you are using the slides, –that you acknowledge my work, and –that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath