Skip to content

Commit

Permalink
Comparisons of InfiniteCardinal with BigInt/BigFloat (#45)
Browse files Browse the repository at this point in the history
* Comparisons of InfiniteCardinal with BigInt/BigFloat

* Tests against infinity
  • Loading branch information
jishnub authored Jul 18, 2023
1 parent fd411a5 commit 489b68b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Infinities"
uuid = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
authors = ["Sheehan Olver <[email protected]>"]
version = "0.1.6"
version = "0.1.7"

[compat]
Aqua = "0.6"
Expand Down
17 changes: 17 additions & 0 deletions src/cardinality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ end
==(::InfiniteCardinal, y::Real) === y
==(x::Real, ::InfiniteCardinal) = x ==

==(::BigInt, ::InfiniteCardinal) = false
==(::InfiniteCardinal, ::BigInt) = false
==(x::BigFloat, ::InfiniteCardinal) = x ==
==(::InfiniteCardinal, x::BigFloat) = x ==

@generated isless(::InfiniteCardinal{N}, ::InfiniteCardinal{M}) where {N,M} = :($(isless(N, M)))
isless(::InfiniteCardinal{0}, ::InfiniteCardinal{0}) = false
isless(x::Real, ::InfiniteCardinal{0}) = isfinite(x)
Expand All @@ -83,6 +88,18 @@ isless(x::InfiniteCardinal, y::AbstractFloat) = false
(::InfiniteCardinal, x::RealInfinity) = false
<(::InfiniteCardinal, x::RealInfinity) = false

for T in (:InfiniteCardinal, :(InfiniteCardinal{0}))
@eval begin
(::BigInt, ::$T) = true
<(::BigInt, ::$T) = true
(::$T, ::BigInt) = false
<(::$T, ::BigInt) = false
(x::BigFloat, ::$T) = true
<(x::BigFloat, ::$T) = x <
(::$T, x::BigFloat) = x
<(::$T, x::BigFloat) = false
end
end

<(::Infinity, ::InfiniteCardinal{0}) = false
<(::Infinity, ::InfiniteCardinal) = true
Expand Down
22 changes: 22 additions & 0 deletions test/test_cardinality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ using Infinities, Base64, Base.Checked, Test
@test !(ℵ₀ < 5) && !(ℵ₀ 5)
@test ℵ₀ > 5 && ℵ₀ 5
@test !(5 > ℵ₀) && !(5 ℵ₀)

@testset "BigInt/BigFloat" begin
for x in (big(2), big(2.0))
@test !(x == ℵ₀)
@test !(ℵ₀ == x)
@test x < ℵ₀
@test !(ℵ₀ < x)
@test x <= ℵ₀
@test !(ℵ₀ <= x)
@test x < InfiniteCardinal{1}()
@test !(InfiniteCardinal{1}() < x)
@test x <= InfiniteCardinal{1}()
@test !(InfiniteCardinal{1}() <= x)
end
@test (ℵ₀ == big(Inf)) == (ℵ₀ == Inf)
@test (big(Inf) == ℵ₀) == (Inf == ℵ₀)
@test (ℵ₀ < big(Inf)) == (ℵ₀ < Inf)
@test (big(Inf) < ℵ₀) == (Inf < ℵ₀)
@test (ℵ₀ <= big(Inf)) == (ℵ₀ <= Inf)
@test (big(Inf) <= ℵ₀) == (Inf <= ℵ₀)
end

end

@testset "min/max" begin
Expand Down

3 comments on commit 489b68b

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlfivefifty Could you tag a release? Thanks!

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/87781

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.7 -m "<description of version>" 489b68b594f436f6b068c222939c9f537d20b928
git push origin v0.1.7

Please sign in to comment.