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 equality for infinities of different types #30

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all 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: 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