cjdoris / Infinity.jl

Representation of infinity in Julia
https://juliahub.com/docs/Infinity/
MIT License
14 stars 4 forks source link

Infinity.jl

Stable Build Status CodeCov

Provides ∞ :: Infinite <: Real representing positive infinity and -∞ is negative infinity.

Extended Types

InfExtendedReal

Promotion between Infinite and some T <: Real will yield either:

The following Base functions are extended for these types:

Additionally there is a submodule Utils exporting infinity-related functions:

InfExtendedTime

Promotion between Infinite and some T <: Dates.TimeType will yield:

The following Base functions are extended for these types:

Installation

In Julia, type ] then run

pkg> add Infinity

Example

julia> 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}(-∞)