compiler construction - associativity of operations regarding floating points -
i trying understand tthe associativity of operations when comes floating points. in lecture notes have, following stated:
"suppose floating-point values store 7 digit of accuracy. considee problem of adding 11 numbers together, 1 of numbers 10^7 , other ten 1.
if small numbers (the 1s) each added large number, 1 @ time, there no effect on number, because small numbers occur in eighth digit of large number ". here understood result 1,000,001.
"however, if small numbers first added , result added large number, result seven-digit accurancy 1.000001 * 10^7"
but both approaches seemed same me: adding 10 numbers larger number. can please clarify problem ? thank you
let's go on first method first. when small numbers added 1 one large number, following happen ten times:
10,000,000 + 1 = 10,000,001
however since floating-point values store 7 digits of accuracy last digit, 8 digit, rounded in seventh digit zero. operation happen 10 times, , value remain 10,000,000.
next let's go on second method. 10 number 1's added first , sum 10. when added 10^7 following happen:
10,000,000 + 10 = 10,000,010
since floating-point values store 7 digits of accuracy number remain!
Comments
Post a Comment