How to display Float64 with many digits in Julia 0.7

This question was posed and answered for Julia 0.6 here.
In Julia 0.7, the same code does not solve the problem:

julia> VERSION
v"0.7.0-beta.65"

julia> v = rand(3)
3-element Array{Float64,1}:
 0.06063439006332505
 0.34977333069792294
 0.9028104608355858 

julia> show(IOContext(stdout, :compact=>false), v)
[0.0606344, 0.349773, 0.90281]

How can I get show to display the non-compact output?

julia> show(IOContext(STDOUT, :compact => false, :limit => false), v)
[0.24458155261742687, 0.06301413396925781, 0.516253732800271]
2 Likes

Thanks a lot!

And what about custom types?

julia> struct MyType{T}
           v :: Vector{T}
       end

julia> a = MyType{Float64}(randn(5))
MyType{Float64}([-0.761001, 0.979279, 1.58786, -0.574857, 0.309297])

julia> show(IOContext(stdout, :compact => false, :limit => false), a)
MyType{Float64}([-0.761001, 0.979279, 1.58786, -0.574857, 0.309297])

julia> show(IOContext(stdout, :compact => false, :limit => false), a.v)
[-0.761001, 0.979279, 1.58786, -0.574857, 0.309297]

1 Like

The :limit property shouldn’t influence the number of printed digits. It seems to me that the requested possibility has been disabled in #24651. I will double-check and make a PR if needed.

Thanks @rfourquet for taking a look on this.

I am not sure, but as far as I can trace this down (for the example above), I think the problem is related to this method of show. There, :compact => true is set, perhaps overwriting what may be defined by the context of io. Is this correct?

As a side remark, the hack proposed here actually works:

julia> Base.show(io::IO, x::Union{Float64,Float32}) = Base.Grisu._show(io, x, Base.Grisu.SHORTEST, 0, true, false)

julia> a = MyType{Float64}(randn(5))
MyType{Float64}([-1.449833577704765, -0.10839395960990496, 3.141203529351768, 0.7843448324558726, -1.3296269838447883])
2 Likes

Yes your analysis is correct, thanks for the report! PR at https://github.com/JuliaLang/julia/pull/27850

2 Likes

Thanks a lot!

1 Like