@@ -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""" 
1012NotANumber() 
@@ -29,6 +31,10 @@ string(::Infinity) = "∞"
2931convert (:: Type{Float64} , :: Infinity ) =  Inf64 
3032convert (:: Type{Float32} , :: Infinity ) =  Inf32 
3133convert (:: Type{Float16} , :: Infinity ) =  Inf16 
34+ Float64 (:: Infinity ) =  convert (Float64, ∞)
35+ Float32 (:: Infinity ) =  convert (Float32, ∞)
36+ Float16 (:: Infinity ) =  convert (Float16, ∞)
37+ BigFloat (:: Infinity ) =  BigFloat (Inf )
3238convert (:: 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))
5460isless (x:: Infinity , y:: AbstractFloat ) =  false 
5561isless (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()
131132RealInfinity (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
136141isinf (:: RealInfinity ) =  true 
137142isfinite (:: RealInfinity ) =  false 
239244
240245min (x:: RealInfinity , y:: RealInfinity ) =  RealInfinity (x. signbit |  y. signbit)
241246max (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 
244249min (x:: RealInfinity , y:: Real ) =  x. signbit ?  x :  y
245250max (x:: RealInfinity , y:: Real ) =  x. signbit ?  y :  x
246251min (x:: RealInfinity , :: Infinity ) =  x
@@ -281,6 +286,7 @@ isfinite(::ComplexInfinity) = false
281286
282287
283288promote_rule (:: Type{Infinity} , :: Type{ComplexInfinity{T}} ) where  T =  ComplexInfinity{T}
289+ promote_rule (:: Type{RealInfinity} , :: Type{ComplexInfinity{T}} ) where  T =  ComplexInfinity{T}
284290convert (:: Type{ComplexInfinity{T}} , :: Infinity ) where  T =  ComplexInfinity {T} ()
285291convert (:: Type{ComplexInfinity} , :: Infinity ) =  ComplexInfinity ()
286292convert (:: Type{ComplexInfinity{T}} , x:: RealInfinity ) where  T =  ComplexInfinity {T} (x)
@@ -292,7 +298,7 @@ angle(x::ComplexInfinity) = π*x.signbit
292298mod (:: 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 
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
387407Base. Checked. checked_add (:: Integer , x:: RealInfinity ) =  x
388408Base. 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
391417Base. to_index (:: Infinity ) =  ∞
392418
0 commit comments