Making the ```BigFloat``` type parametric

Hello!

I am someone who is very enthusiastic about Julia language, and here I would like to comment about the BigFloat type, as well as make a proposal.

The precision of BigFloat depends on a global state, which you can change with setprecision:

julia> setprecision(2)
2

julia> BigFloat("0.3")
0.25

julia> setprecision(100)
100

julia> BigFloat("0.3")
0.30000000000000000000000000000016

The problem I see is that precision may be changed, without the user even being aware of.

julia> function f()
           setprecision(2)
       end
f (generic function with 1 method)

julia> function double(x)
           f()
           return 2*x
       end
double (generic function with 1 method)

julia> setprecision(100)
100

julia> double(BigFloat("0.3"))
0.50

In a code that is very big and uses many library functions, it might be very difficult to verify that the precision of the BigFloat type doesn’t change along the way.

Would it be a good idea to have a parametric type BigFloat{n <: Int}?

This would be a good idea but would require rewriting BigFloat in Julia

1 Like

See this discussion in GitHub: https://github.com/JuliaLang/julia/issues/10040

1 Like

Nice! I am reading this discussionn