Provides ∞ :: Infinite <: Real representing positive infinity and -∞ is negative infinity.
Promotion between Infinite and some T <: Real will yield either:
Titself if it can natively represent infinity (e.g.Float64,Rational); orInfExtendedReal{T} <: Realotherwise, which represents positive/negative infinity, or a finite value of typeT. (See the examples.)
The following Base functions are extended for these types:
- Arithmetic:
typemin,typemax,+,-,*,/ - Comparison:
==,<,≤,hash,signbit,sign,isfinite,isinf,isapprox - Conversion:
promote,convert,float,widen,big - Random:
rand(Infinite)
Additionally there is a submodule Utils exporting infinity-related functions:
posinf(T),neginf(T): positive or negative infinity as aTif possible, or elsenothinghasposinf(T),hasneginf(T): true ifTcontains positive or negative infinityhasinf(T): true ifTcontains both positive and negative infinity (this is used to decide to promote toInfExtendedRealor not)isposinf(x),isneginf(x): true ifxis positive or negative infinity
Promotion between Infinite and some T <: Dates.TimeType will yield:
InfExtendedTime{T} <: Dates.TimeType, which represents positive/negative infinity, or a finite value of typeT. (See the examples.)
The following Base functions are extended for these types:
- Arithmetic:
typemin,typemax,T+Period,T-Period - Comparison:
==.<,≤,hash,isfinite,isinf - Conversion:
promote,convert
In Julia, type ] then run
pkg> add Infinityjulia> using Infinity
julia> x = [1,2,3,∞,-1,-∞]
6-element Array{InfExtendedReal{Int64},1}:
InfExtendedReal{Int64}(1)
InfExtendedReal{Int64}(2)
InfExtendedReal{Int64}(3)
InfExtendedReal{Int64}(∞)
InfExtendedReal{Int64}(-1)
InfExtendedReal{Int64}(-∞)
julia> sort(x)
6-element Array{InfExtendedReal{Int64},1}:
InfExtendedReal{Int64}(-∞)
InfExtendedReal{Int64}(-1)
InfExtendedReal{Int64}(1)
InfExtendedReal{Int64}(2)
InfExtendedReal{Int64}(3)
InfExtendedReal{Int64}(∞)
julia> float(x)
6-element Array{Float64,1}:
1.0
2.0
3.0
Inf
-1.0
-Inf
julia> using Dates
julia> x = [Date(2012, 1, 1), Date(2013, 1, 1), Date(2013, 1, 2), ∞, Date(1987, 1, 1), -∞]
6-element Array{InfExtendedTime{Date},1}:
InfExtendedTime{Date}(2012-01-01)
InfExtendedTime{Date}(2013-01-01)
InfExtendedTime{Date}(2013-01-02)
InfExtendedTime{Date}(∞)
InfExtendedTime{Date}(1987-01-01)
InfExtendedTime{Date}(-∞)
julia> sort(x)
6-element Array{InfExtendedTime{Date},1}:
InfExtendedTime{Date}(-∞)
InfExtendedTime{Date}(1987-01-01)
InfExtendedTime{Date}(2012-01-01)
InfExtendedTime{Date}(2013-01-01)
InfExtendedTime{Date}(2013-01-02)
InfExtendedTime{Date}(∞)
julia> Day(1) + x
6-element Array{InfExtendedTime{Date},1}:
InfExtendedTime{Date}(2012-01-02)
InfExtendedTime{Date}(2013-01-02)
InfExtendedTime{Date}(2013-01-03)
InfExtendedTime{Date}(∞)
InfExtendedTime{Date}(1987-01-02)
InfExtendedTime{Date}(-∞)