numerical - Using MPFR And Adding - How many Digits are Correct? -


i have pretty easy question (i think). as i've tried, can not find answer question.

i creating function, want user enter 2 numbers. first the number of terms of infinite series add together. second number of digits user truncated sum accurate to.

say terms of sequence a_i. how precision n, required in mpfr ensure result of adding these a_i i=0 user's entered value needed guarantee number of digits user needs?

by way, i'm adding a_i in naive way.

any appreciated.

thanks,

rick

you can convert between decimal digits of precision, d, , binary digits of precision, b, logarithms

b = d × log(10) / log(2)

a little rearranging shows why

b × log(2) = d × log(10)
log(2b) = log(10d)
2b = 10d

each term of series (and each addition) introduce rounding error @ least significant digit so, assuming each of t terms involves n (two argument) arithmetic operations, want add extra

log(t * (n+2))/log(2)

bits.

you'll need round number of bits of precision up sure have enough room decimal digits of precision

b = ceil((d*log(10.0) + log(t*(n+2)))/log(2.0)); 

finally, should aware terms may introduce cancellation errors, in case simple calculation dramatically underestimate required number of bits, assuming i've got right in first place ;-)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -