Skip to content

Commit e0704f8

Browse files
committed
Increase coverage
1 parent 4c74c87 commit e0704f8

File tree

5 files changed

+193
-57
lines changed

5 files changed

+193
-57
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ version = "0.0.1"
77
julia = "1"
88

99
[extras]
10+
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
1011
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1112

1213
[targets]
13-
test = ["Test"]
14+
test = ["Base64", "Test"]

src/Infinities.jl

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import Base: angle, isone, iszero, isinf, isfinite, abs, one, zero, isless,
44
+, -, *, ==, <, , >, , fld, cld, div, mod, min, max, sign, signbit,
55
string, show, promote_rule, convert
66

7-
export ∞, Infinity, RealInfinity, ComplexInfinity, NotANumber
7+
export ∞, ℵ₀, ℵ₁, RealInfinity, ComplexInfinity, NotANumber
8+
# The following is commented out for now to avoid conflicts with Infinity.jl
9+
# export Infinity
810

911
"""
1012
NotANumber()
@@ -29,6 +31,10 @@ string(::Infinity) = "∞"
2931
convert(::Type{Float64}, ::Infinity) = Inf64
3032
convert(::Type{Float32}, ::Infinity) = Inf32
3133
convert(::Type{Float16}, ::Infinity) = Inf16
34+
Float64(::Infinity) = convert(Float64, ∞)
35+
Float32(::Infinity) = convert(Float32, ∞)
36+
Float16(::Infinity) = convert(Float16, ∞)
37+
BigFloat(::Infinity) = BigFloat(Inf)
3238
convert(::Type{AF}, ::Infinity) where AF<:AbstractFloat = convert(AF, Inf)
3339

3440

@@ -54,20 +60,15 @@ isless(x::AbstractFloat, y::Infinity) = isless(x, convert(typeof(x), y))
5460
isless(x::Infinity, y::AbstractFloat) = false
5561
isless(x::Infinity, y::Real) = false
5662

63+
+(::Infinity) =
5764
+(::Infinity, ::Infinity) =
5865
+(::Number, y::Infinity) =
5966
+(::Infinity, ::Number) =
6067
-(::Infinity, ::Number) =
61-
-(x::Number, ::Infinity) = x + (-∞)
6268

6369
+(::Integer, y::Infinity) =
6470
+(::Infinity, ::Integer) =
6571
-(::Infinity, ::Integer) =
66-
-(x::Integer, ::Infinity) = x + (-∞)
67-
+(::Complex, y::Infinity) =
68-
+(::Infinity, ::Complex) =
69-
-(::Infinity, ::Complex) =
70-
-(x::Complex, ::Infinity) = x + (-∞)
7172

7273
-(::Infinity, ::Infinity) = NotANumber()
7374

@@ -131,7 +132,11 @@ RealInfinity(::Infinity) = RealInfinity()
131132
RealInfinity(x::RealInfinity) = x
132133

133134
-(::Infinity) = RealInfinity(true)
134-
+(::Infinity) =
135+
-(x::Number, ::Infinity) = x + (-∞)
136+
-(x::Integer, ::Infinity) = x + (-∞)
137+
-(x::Complex, ::Infinity) = x + (-∞)
138+
-(x::Complex{Bool}, ::Infinity) = x + (-∞)
139+
135140

136141
isinf(::RealInfinity) = true
137142
isfinite(::RealInfinity) = false
@@ -239,8 +244,8 @@ end
239244

240245
min(x::RealInfinity, y::RealInfinity) = RealInfinity(x.signbit | y.signbit)
241246
max(x::RealInfinity, y::RealInfinity) = RealInfinity(x.signbit & y.signbit)
242-
min(x::Real, y::RealInfinity) = y.signbit ? x : y
243-
max(x::Real, y::RealInfinity) = y.signbit ? y : x
247+
min(x::Real, y::RealInfinity) = y.signbit ? y : x
248+
max(x::Real, y::RealInfinity) = y.signbit ? x : y
244249
min(x::RealInfinity, y::Real) = x.signbit ? x : y
245250
max(x::RealInfinity, y::Real) = x.signbit ? y : x
246251
min(x::RealInfinity, ::Infinity) = x
@@ -281,6 +286,7 @@ isfinite(::ComplexInfinity) = false
281286

282287

283288
promote_rule(::Type{Infinity}, ::Type{ComplexInfinity{T}}) where T = ComplexInfinity{T}
289+
promote_rule(::Type{RealInfinity}, ::Type{ComplexInfinity{T}}) where T = ComplexInfinity{T}
284290
convert(::Type{ComplexInfinity{T}}, ::Infinity) where T = ComplexInfinity{T}()
285291
convert(::Type{ComplexInfinity}, ::Infinity) = ComplexInfinity()
286292
convert(::Type{ComplexInfinity{T}}, x::RealInfinity) where T = ComplexInfinity{T}(x)
@@ -292,7 +298,7 @@ angle(x::ComplexInfinity) = π*x.signbit
292298
mod(::ComplexInfinity{<:Integer}, ::Integer) = NotANumber()
293299

294300

295-
show(io::IO, x::ComplexInfinity) = print(io, "$(exp(im*π*x.signbit))")
301+
show(io::IO, x::ComplexInfinity) = print(io, "exp($(x.signbit)*im*π)∞")
296302

297303
==(x::ComplexInfinity, y::Infinity) = x.signbit == 0
298304
==(y::Infinity, x::ComplexInfinity) = x.signbit == 0
@@ -323,6 +329,20 @@ end
323329
-(y::ComplexInfinity, ::Number) = y
324330
-(::Number, y::ComplexInfinity) = -y
325331

332+
+(::Complex, ::Infinity) = ComplexInfinity()
333+
+(::Infinity, ::Complex) = ComplexInfinity()
334+
-(::Infinity, ::Complex) = ComplexInfinity()
335+
+(::Complex{Bool}, ::Infinity) = ComplexInfinity()
336+
+(::Infinity, ::Complex{Bool}) = ComplexInfinity()
337+
-(::Infinity, ::Complex{Bool}) = ComplexInfinity()
338+
339+
+(::Complex, y::RealInfinity) = ComplexInfinity(y)
340+
+(y::RealInfinity, ::Complex) = ComplexInfinity(y)
341+
-(y::RealInfinity, ::Complex) = ComplexInfinity(y)
342+
+(::Complex{Bool}, y::RealInfinity) = ComplexInfinity(y)
343+
+(y::RealInfinity, ::Complex{Bool}) = ComplexInfinity(y)
344+
-(y::RealInfinity, ::Complex{Bool}) = ComplexInfinity(y)
345+
326346

327347
# ⊻ is xor
328348
*(a::ComplexInfinity{Bool}, b::ComplexInfinity{Bool}) = ComplexInfinity(a.signbit b.signbit)
@@ -387,6 +407,12 @@ Base.Checked.checked_sub(x::RealInfinity, ::Integer) = x
387407
Base.Checked.checked_add(::Integer, x::RealInfinity) = x
388408
Base.Checked.checked_add(x::RealInfinity, ::Integer) = x
389409

410+
Base.Checked.checked_mul(x::Integer, ::Infinity) = sign(x)*
411+
Base.Checked.checked_mul(::Infinity, x::Integer) = sign(x)*
412+
Base.Checked.checked_mul(x::Integer, ::RealInfinity) = sign(x)*
413+
Base.Checked.checked_mul(::RealInfinity, x::Integer) = sign(x)*
414+
415+
390416

391417
Base.to_index(::Infinity) =
392418

src/cardinality.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ end
2929

3030
abs(a::InfiniteCardinal) = a
3131
zero(::InfiniteCardinal) = 0
32+
one(::InfiniteCardinal) = 1
3233

3334
for OP in (:<, :)
3435
@eval begin
@@ -50,7 +51,5 @@ const ℵ₁ = InfiniteCardinal{1}()
5051
string(::InfiniteCardinal{0}) = "ℵ₀"
5152
string(::InfiniteCardinal{1}) = "ℵ₁"
5253

53-
show(io::IO, F::InfiniteCardinal{0}) where N =
54-
print(io, "ℵ₀")
55-
show(io::IO, F::InfiniteCardinal{1}) where N =
56-
print(io, "ℵ₁")
54+
show(io::IO, F::InfiniteCardinal{0}) where N = print(io, "ℵ₀")
55+
show(io::IO, F::InfiniteCardinal{1}) where N = print(io, "ℵ₁")

0 commit comments

Comments
 (0)