The following function computes Euler's constant e = exp(1.0) to n digits
*exactly* (returning it as string):
function dropletE(n::Int)
a = fill(1, n+2)
E = "2."
for i in 1:n
a = 10 * a
for j in (n+2):-1:2
a[j-1] = a[j-1] + div(a[j], j+1)
a[j] = mod(a[j], j+1)
end
E = E * string(div(a[1], 2))
a[1] = mod(a[1], 2)
end
return E
end
Comparing it with e calculated in Julia with the Big number class shows
that the computation in Julia is only correct up to the 76th digit (of 78
digits shown).
julia> dropletE(100)
"2.71828182845904523536028747135266249775724709369995
95749669676277240766303535475945713821785251664274"
julia> exp(big(1.0)) # or simply:
big(e)
2.71828182845904523536028747135266249775724709369995
9574966967627724076630353555e+00 with 256 bits of precision
This corresponds well to the fact that Julia is utilizing the MPFR library
(?) "with 256 bits of precision" only.
Question: How can I change this behavior and force Julia to apply more
digits, e.g. 4096 bits, to get about 1200 correct decimal digits. Is there
a parameter one can set, or do I need to recompile Julia with a certain
option?
[In R, with the MPFR package, one can set the number of digits with every
single number defined as 'big', i.e. as MPFR number.]