Skip to content

Inconsistent behaviour when comparing -0.0 with 0.0 #168

@andreasvarga

Description

@andreasvarga

The following behaviour I detected performing the function issymmetric on a symmetric matrix (thus preventing a correct test).

julia> C = Matrix(Hermitian(Complex{Double64}[1 0;0 1]))
2×2 Matrix{Complex{Double64}}:
 1.0 + 0.0im  0.0 + 0.0im
 0.0 - 0.0im  1.0 + 0.0im

julia> ishermitian(C)
true

julia> Ce = [real(C) imag(C); -imag(C) real(C)]  # construct a symmetric real matrix 
4×4 Matrix{Double64}:
  1.0   0.0   0.0  0.0
  0.0   1.0  -0.0  0.0
 -0.0  -0.0   1.0  0.0
  0.0  -0.0   0.0  1.0

julia> issymmetric(Ce)  # this test is in my opinion incorrect
false

julia> Ce == transpose(Ce)   # the matrix is symmetric as expected
true

The invalid test can be simply reproduced as shown bellow:


julia> y = -Double64(0)
-0.0

julia> z = Double64(0)
0.0

julia> y === z
false

julia> y == z
true

julia> y != z
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions