BigFloat precision issue


julia> N=BigFloat(2.0,2048);
julia> S=sqrt(N);
julia> S^2-N
julia> S.prec
julia> N.prec

Why only 256 precision from the sqrt?

Jean-Pierre Dussault

julia> setprecision(2048)

julia> S = sqrt(N);

julia> S.prec

But perhaps the precision of the output should be inherited from the input argument?




I agree - I think that operations on BigFloats should always promote to the largest precision of the inputs.

That probably was difficult to do when the precision was only controlled by setprecision, but now that it can be specified in the constructor, it just makes sense.


A workaround can be to use a setprecision block, like:

julia> setprecision(BigFloat, 2048) do
       N = BigFloat(2.0)
       S = sqrt(N)
       @show N.prec
       @show S.prec
N.prec = 2048
S.prec = 2048

I tend to use those blocks anyway, but I sure did also assume that they promoted to the largest precision when working outside of a block.