From 68b0f21039d4aa148680a65ac558f8551a32785e Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 11 Aug 2020 15:54:03 -0500 Subject: [PATCH] Fix equality for infinities of different types --- src/infinite/comparison.jl | 2 ++ test/infextendedreal.jl | 1 + test/infinite.jl | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/src/infinite/comparison.jl b/src/infinite/comparison.jl index b324490..ab76e28 100644 --- a/src/infinite/comparison.jl +++ b/src/infinite/comparison.jl @@ -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) diff --git a/test/infextendedreal.jl b/test/infextendedreal.jl index 0aacf88..a490f20 100644 --- a/test/infextendedreal.jl +++ b/test/infextendedreal.jl @@ -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) diff --git a/test/infinite.jl b/test/infinite.jl index 36785c0..493eb0f 100644 --- a/test/infinite.jl +++ b/test/infinite.jl @@ -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