1.2 Round Off Errors and Computer Arithmetic
1.2 Round Off Errors and Computer Arithmetic
Round-off Errors
and Computer
Arithmetic
Sec:1.2 Round-off Errors and Computer Arithmetic
2 Why?
Example:
( √ 19 ) =¿ round-off errors are directly related to the manner
in which numbers are stored in a computer.
*binary system
floating point numbers
Error = 0.000000000000004
>> format short
relative error = >> pi
3.1416
>> format long
>> pi
3.141592653589793
Sec:1.2 Round-off Errors and Computer Arithmetic
exponent fraction
In 1985, the IEEE (Institute for Electrical and Electronic
Engineers) published a report called Binary Floating
Example:
Point Arithmetic Standard 754–1985.
0 10000000011 1011100100010000000000000000000000000000000000000000
52-bit fraction
1011100100010000000000000000000000000000000000000000
1 3 4 5 8 12
1 1 1 1 1 1
𝒇 =1 ∙( ) +1 ∙( ) +1∙ ( ) +1 ∙( ) +1∙( ) +1 ∙ ( )
2 2 2 2 2 2
1 1 1 1 1 1
𝒇 = + +
2 8 16 32 256 4096¿ 𝟎 .𝟕𝟐𝟐𝟗𝟎𝟎𝟑𝟗𝟎𝟔𝟐𝟓
+ + +
¿ 𝟐𝟕 . 𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓
Sec:1.2 Round-off Errors and Computer Arithmetic
Use the 64-bit long real format to find the decimal equivalent of the following floating-
point machine number.
0 01111111110 1001001100000000000000000000000000000000000000000000
S=0
c = 2^9+2^8+2^7+2^6+2^5+2^4+2^3+2^2+2^1= 1022
𝟏+ 𝟏 + 𝟏 + 𝟏
𝟏 𝟒 𝟕 𝟖
𝟏 𝟏 𝟏 𝟏
𝒇 =( ) +( ) +( ) +( ) ¿ = 0.57421875
𝟐 𝟐 𝟐 𝟐 𝟐 𝟏𝟔 𝟏𝟐𝟖 𝟐𝟓𝟔
0 01111111110 1001001100000000000000000000000000000000000000000000
Example:
1 01111111110 1001001100000000000000000000000000000000000000000000
−𝟎 . 𝟕𝟖𝟕𝟏𝟎𝟗𝟑𝟕𝟓
¿(− 𝟏)𝟏 × 𝟐𝟏𝟎 𝟐𝟐−𝟏𝟎𝟐𝟑 × (𝟏+𝟎 . 𝟓𝟕𝟒𝟐𝟏𝟖𝟕𝟓 ) ¿
Sec:1.2 Round-off Errors and Computer Arithmetic
0 11111111111 1111111111111111111111111111111111111111111111111111
S=0 c = 2046 𝒇 =𝟏 − 𝟐− 𝟓𝟐
𝒏𝒖𝒎𝒃𝒆𝒓
=(− 𝟏)𝟎 × 𝟐𝟐𝟎𝟒𝟔 −𝟏𝟎𝟐𝟑 × (𝟐 − 𝟐− 𝟓𝟐 ) = 0.1797693134862316e+309
>> 2^1023*(2-2^(-52))
1.797693134862316e+308
>>2^1024-2^971
Inf
S=0 c=1 𝒇 =𝟎
𝟎 𝟏− 𝟏𝟎𝟐𝟑
𝒏𝒖𝒎𝒃𝒆𝒓 =(− 𝟏 ) × 𝟐 ×(𝟏 +𝟎 ) = 2.225073858507201e-308
𝑥 ∗
0 10000000011 1011100100010000000000000000000000000000000000000000
0 10000000011 1011100100010000000000000000000000000000000000000001
𝟐𝟕 .𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓+ 𝒙 ∗
=¿27.5664062500000017763568394002504646778106689453125
𝟐
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
5-digit decimal machine numbers
Example:
The floating-point form of y, denoted
fl(y), is obtained by terminating the y = π = 0.314159265 . . . × .
mantissa of y at k decimal digits.
two common ways of termination chopping fl(y) = 0.31415 ×
chopping
rounding fl(y) = 0.31416 ×
rounding
Sec:1.2 Round-off Errors and Computer Arithmetic
Example: Example:
significant digits
(or figures)
Sec:1.2 Round-off Errors and Computer Arithmetic
significant digits
(or figures)
Example:
Determine the significant digits
𝑝=0.1 𝑝 ∗=0.10005
Example:
Determine the significant digits
𝑝=5000 𝑝 ∗=5002.4
Example:
Suppose
that x = and y =
Use five-digit chopping for calculating x + y
x = fl(x) = 0.71428 ×
y = fl(y) = 0.33333 ×
x ⊕ y = fl(0.71428 × + 0.33333 × ),
number 1.0476× is said to approximate to
The
= fl(1.04761× )= 1.0476× 4 significant digits
Sec:1.2 Round-off Errors and Computer Arithmetic
𝑓 ( 𝑥 )=¿
Remark The decreased error in this example is due to the reduction in computations from
four multiplications and three additions to two multiplications and three additions.
One way to reduce round-off error is to reduce the number of computations.
Polynomials should always be expressed in nested form
Sec:1.2 Round-off Errors and Computer Arithmetic
round-off error can also be reduced by
rationalizing the numerator
rearranging calculations
Example: