Skip to content

Commit

Permalink
Fix equality for infinities of different types
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Aug 11, 2020
1 parent 0d8fa31 commit 68b0f21
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/infinite/comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Base.isinf(x::Infinite) = true
Base.iszero(::Infinite) = false

Base.:(==)(x::Infinite, y::Infinite) = x.signbit == y.signbit
Base.:(==)(x::Infinite, y::Real) = isinf(y) && signbit(x) == signbit(y)
Base.:(==)(x::Real, y::Infinite) = y == x

Base.hash(x::Infinite, h::UInt) = hash(isposinf(x) ? Inf : -Inf, h)

Expand Down
1 change: 1 addition & 0 deletions test/infextendedreal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
@test InfExtendedReal(5) == 5
@test InfExtendedReal(7) == 7.0
@test InfExtendedReal(4) != InfExtendedReal(1)
@test InfExtendedReal(Inf) == InfExtendedReal(∞)

@test hash(InfExtendedReal(3)) == hash(3)

Expand Down
4 changes: 4 additions & 0 deletions test/infinite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
@test !iszero(x)
@test !iszero(-x)
@test x == x
@test x == Inf
@test Inf == x
@test x != -x
@test x != -Inf
@test Inf != -x
@test hash(x) != hash(-x)
@test -x < x
@test x > -x
Expand Down

0 comments on commit 68b0f21

Please sign in to comment.