Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #37756: Correct formatting of hexadecimal imaginary parts #57803

Merged
merged 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function show(io::IO, z::Complex)
print(io, compact ? "+" : " + ")
show(io, i)
end
if !(isa(i,Integer) && !isa(i,Bool) || isa(i,AbstractFloat) && isfinite(i))
if !(isa(i,Signed) || isa(i,AbstractFloat) && isfinite(i))
print(io, "*")
end
print(io, "im")
Expand Down
20 changes: 16 additions & 4 deletions test/complex.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using LinearAlgebra
using Test

@test reim(2 + 3im) == (2, 3)

Expand All @@ -24,10 +25,21 @@ for T in (Int64, Float64)
@test complex(Complex{T}) == Complex{T}
end

#show
@test sprint(show, complex(1, 0), context=:compact => true) == "1+0im"
@test sprint(show, complex(true, true)) == "Complex(true,true)"
@test sprint(show, Complex{Int8}(0, typemin(Int8))) == "0 - 128im"
@testset "show" begin
@test sprint(show, complex(1, 0), context=:compact => true) == "1+0im"
@test sprint(show, complex(true, true)) == "Complex(true,true)"
@test sprint(show, Complex{Int8}(0, typemin(Int8))) == "0 - 128im"
@test sprint(show, complex(typemin(Int16), typemax(Int16))) == "-32768 + 32767im"
@test sprint(show, complex(0x26, 0x26), context=:compact => true) == "0x26+0x26*im"
@test sprint(show, complex(0o77, 0o77), context=:compact => true) == "0x3f+0x3f*im"
@test sprint(show, complex(0b10, 0b11)) == "0x02 + 0x03*im"
@test sprint(show, complex(-0x1A, 0x2F), context=:compact => true) == "0xe6+0x2f*im"
@test sprint(show, complex(typemax(UInt16), typemin(UInt16))) =="0xffff + 0x0000*im"
@test sprint(show, complex(-Inf, Inf)) == "-Inf + Inf*im"
@test sprint(show, complex(-Inf, NaN)) == "-Inf + NaN*im"
@test sprint(show, complex(0, -Inf)) == "0.0 - Inf*im"
end


@testset "unary operator on complex boolean" begin
@test +Complex(true, true) === Complex(1, 1)
Expand Down
Loading