Professional Documents
Culture Documents
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.
* Numbers such as π, e, or cannot be expressed by
a fixed number of significant figures
*numbers on the computer are represented with a
binary, or base-2, system.
*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
𝒄 =1024 +0 + ⋯ ⋯ ⋯ +2 +1
𝒄 =1027
Sec:1.2 Round-off Errors and Computer Arithmetic
𝒄 =𝟏𝟎𝟐𝟕 𝒔 𝒄 − 𝟏𝟎𝟐𝟑
¿ (−𝟏) 𝟐 (𝟏+ 𝒇 )
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 ¿𝟎.𝟕𝟐𝟐𝟗𝟎𝟎𝟑𝟗𝟎𝟔𝟐𝟓
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 𝒇 =𝟏 − 𝟐
>> 2^1023*(2-2^(-52))
1.797693134862316e+308
>>2^1024-2^971
Inf
S=0 c=1 𝒇 =𝟎
𝑥∗
0 10000000011 1011100100010000000000000000000000000000000000000000
0 10000000011 1011100100010000000000000000000000000000000000000001
𝟐𝟕.𝟓𝟔𝟔𝟒𝟎𝟔𝟐𝟓 +𝒙 ∗
=¿27.5664062500000017763568394002504646778106689453125
𝟐
Sec:1.2 Round-off Errors and Computer Arithmetic
Largest floating point
Binary Machine Numbers 0 11111111111 1111111111111111111111111111111111111111111111111111
(floating-point number)
s c f
Example:
0 10000000011 1011100100010000000000000000000000000000000000000000
¿𝟎.𝟕𝟐𝟐𝟗𝟎𝟎𝟑𝟗𝟎𝟔𝟐𝟓
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Determine the actual, absolute,
and relative errors when
approximating by
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Determine the actual, absolute,
and relative errors when
approximating by
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Determine the significant digits
𝑝=0.1 𝑝 ∗=0.10005
0.00005 −4
=0.0005 ≤ 5× 10
0.1
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Determine the significant digits
𝑝=5000 𝑝 ∗=5002.4
2.4
=0.00048=4.8 ×10 −4 ≤ 5 ×10 −4
5000
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Determine the significant digits
≤ 5 × 10
−𝑡
𝑡 =?
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Suppose that x = and y =
Use five-digit chopping for calculating x + y
x= fl(x) =
y= fl(y) =
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Suppose that x = and y =
Use five-digit chopping for calculating x + y
x= fl(x) =
y= fl(y) =
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Suppose that x = and y =
Use five-digit chopping for calculating x + y
x= fl(x) = 0.71428 ×
y= fl(y) = 0.33333 ×
Sec:1.2 Round-off Errors and Computer Arithmetic
Example:
Suppose that x= and u =0.714251
x=
Use five-digit chopping for calculating x -u
This approximation has a small absolute error but a large relative error
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: