julia> N=BigFloat(2.0,2048);
julia> S=sqrt(N);
julia> S^2-N
-1.727233711018888925077270372560079914223200072887256277004740694033718360632485e-77
julia> S.prec
256
julia> N.prec
2048
Why only 256 precision from the sqrt?
Jean-Pierre Dussault
julia> N=BigFloat(2.0,2048);
julia> S=sqrt(N);
julia> S^2-N
-1.727233711018888925077270372560079914223200072887256277004740694033718360632485e-77
julia> S.prec
256
julia> N.prec
2048
Why only 256 precision from the sqrt?
Jean-Pierre Dussault
julia> setprecision(2048)
2048
julia> S = sqrt(N);
julia> S.prec
2048
But perhaps the precision of the output should be inherited from the input argument?
Thanks!
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
end
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.