Skip to content

Commit

Permalink
fix JuliaLang#46051, OOB string index in printing irrationals (JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 18, 2022
1 parent 29586ef commit 6b91a82
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function show(io::IO, ::MIME"text/plain", x::Irrational{sym}) where {sym}
if get(io, :compact, false)
print(io, sym)
else
print(io, sym, " = ", string(float(x))[1:15], "...")
print(io, sym, " = ", string(float(x))[1:min(end,15)], "...")
end
end

Expand Down
4 changes: 3 additions & 1 deletion test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,13 @@ end

@test sqrt(2) == 1.4142135623730951
end
Base.@irrational i46051 4863.185427757 1548big(pi)
@testset "Irrational printing" begin
@test sprint(show, "text/plain", π) == "π = 3.1415926535897..."
@test sprint(show, "text/plain", π, context=:compact => true) == "π"
@test sprint(show, π) == "π"

# issue #46051
@test sprint(show, "text/plain", i46051) == "i46051 = 4863.185427757..."
end
@testset "issue #6365" begin
for T in (Float32, Float64)
Expand Down

0 comments on commit 6b91a82

Please sign in to comment.