Вы находитесь на странице: 1из 12

SE301

Numerical Methods

2. Number Representation

SE301_04 (c)Al-AMER2003 1
Outlines
 Number Representation
 Normalized Floating Point
Representation
 Rounding and Chopping

SE301_04 (c)Al-AMER2003 2
Representing Real Numbers
 You are familiar with the decimal system
312.45 = 3 ×10 2 + 1×101 + 2 ×10 0 + 4 ×10 −1 + 5 ×10 −2

 Decimal System Base =10 , Digits(0,1,…9)


 Standard Representations
± 3 1 2 . 4 5
sign integral fraction
part part

SE301_04 (c)Al-AMER2003 3
Normalized Floating Point
Representation
 Normalized Floating Point Representation
± 0. d1 d 2 d 3 d 4 × 10 n
sign mantissa exponent

 No integral part,
d1 ≠ 0; n : integer
 Advantage Efficient in representing very small or very large
numbers

SE301_04 (c)Al-AMER2003 4
Binary System
 Binary System Base=2, Digits{0,1}
± 0. 1 b2 b3 b4 × 2 n
sign mantissa exponent

b1 ≠ 0 ⇒ b1 = 1

−1 −2 −3
(0.101) 2 = (1× 2 + 0 × 2 + 1× 2 )10 = (0.625)10

SE301_04 (c)Al-AMER2003 5
Fact
 Number that have finite expansion in one numbering
system may have an infinite expansion in another
numbering system

(0.1)10 = (0.000110011001100...) 2

 You can never represent 0.1 exactly in any computer

SE301_04 (c)Al-AMER2003 6
Representation
Hypothetical Machine
Mantissa 2 bits exponent 2 bit sign 1 bit

Possible machine numbers


.25 .3125 .375 .4375 .5 .625 .75 .875 1 1.25 1.5 1.75

SE301_04 (c)Al-AMER2003 7
Representation
1

0.8

0.6

0.4

0.2

­0.2

­0.4

­0.6

­0.8

­1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

SE301_04 (c)Al-AMER2003 8
Remarks

 Numbers that can be exactly represented are called


machine numbers
 Difference between machine numbers is not uniform
sum of machine numbers is not necessarily a machine
number
0.25 + .3125 =0.5625 (not a machine number)

SE301_04 (c)Al-AMER2003 9
Rounding and Choping

 Rounding: Replace the number by the nearest


machine number
 Chopping: Throw all extra digits

SE301_04 (c)Al-AMER2003 10
Remarks
Hypothetical Machine:
32 bits are used to represent
floating point numbers

1 bit 23 bits 8 bits


sign mantissa Exponent

0.1 is not a machine number


fl (0.1) is the floating point representation of 0.1

x − fl ( x) 1 − 23
for any x in the range ≤ (2 )
x 2
SE301_04 (c)Al-AMER2003 11
Error in Representations
for any x in the range
fl ( x) = x(1 + δ ) where δ ≤ 2 − 24
How large can the error be when you multiply two numbers
x * y?
fl(x) = x( 1 + δ1 )
fl ( y ) = y (1 + δ 2 )
fl ( fl ( x) * fl ( y )) = ( x( 1 + δ1 )y (1 + δ 2 ) ) (1 + δ 3 )

SE301_04 (c)Al-AMER2003 12

Вам также может понравиться