Skip to content

Commit

Permalink
Merge pull request #30 from omus/cv/eq-fix
Browse files Browse the repository at this point in the history
Fix equality for infinities of different types
  • Loading branch information
cjdoris authored Aug 12, 2020
2 parents 5b5decc + 68b0f21 commit c8cf5e1
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 @@ -128,6 +128,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 @@ -63,7 +63,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 c8cf5e1

Please sign in to comment.