Provides ∞ :: Infinite <: Real
representing positive infinity and -∞
is negative infinity.
Promotion between Infinite
and some T <: Real
will yield either:
T
itself if it can natively represent infinity (e.g.Float64
,Rational
); orInfExtended{T} <: Real
otherwise, which represents the union ofT
andInfinite
. (See the examples.)
The following Base
functions are extended for these types:
- Arithmetic:
+
,-
,*
,/
- 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 aT
if possible, or elsenothing
hasposinf(T)
,hasneginf(T)
: true ifT
contains positive or negative infinityhasinf(T)
: true ifT
contains both positive and negative infinity (this is used to decide to promote toInfExtended
or not)isposinf(x)
,isneginf(x)
: true ifx
is positive or negative infinity
In Julia, type ]
then run
pkg> install https://github.com/cjdoris/Infinity.jl
julia> using Infinity
julia> x = [1,2,3,∞,-1,-∞]
6-element Array{InfExtended{Int64},1}:
1
2
3
∞
-1
-∞
julia> sort(x)
6-element Array{InfExtended{Int64},1}:
-∞
-1
1
2
3
∞
julia> float(x)
6-element Array{Float64,1}:
1.0
2.0
3.0
Inf
-1.0
Inf