Required API functions
Each package creating a new ThickNumber subtype must implement:
ThickNumbers.loval — Functionloval(x::ThickNumber)The value representing the lower limit of the span of x. loval must be implemented by any subtype of ThickNumber.
Examples
julia> loval(Interval(1, 2)) # suppose Interval{T} <: ThickNumber{T}
1ThickNumbers.hival — Functionhival(x::ThickNumber)The value representing the upper limit of the span of x. hival must be implemented by any subtype of ThickNumber.
Examples
julia> hival(Interval(1, 2)) # suppose Interval{T} <: ThickNumber{T}
2ThickNumbers.basetype — Functionbasetype(::Type{TN}) where TN<:ThickNumberStrip the valuetype from TN.
Interface requirements
basetype must be implemented by all ThickNumber subtypes.
Examples
In a package implementing Interval you would define
ThickNumbers.basetype(::Type{Interval{T}}) where T = Interval
ThickNumbers.basetype(::Type{Interval}) = Intervalso that
julia> basetype(Interval{Float64})
IntervalThis can be used to construct valuetype-agnostic ThickNumbers:
julia> lohi(basetype(Interval{Float64}), 1, 2))
Interval{Int64}(1, 2)If possible, you should also implement:
ThickNumbers.lohi — Functionlohi(::Type{TN}, lo, hi) where TN<:ThickNumberConstruct a TN from its lo and hi values.
Interface requirements
lohi must be implemented by all ThickNumber subtypes.
If
x = lohi(TN, lo, hi)succeeds without throwing an error, then it is required that
typeof(x) <: TN
lo ∈ x
hi ∈ x
lo ≈ loval(x)
hi ≈ hival(x)For the latter two, exact equality is not required; this allows for roundoff error (in case TN is parametrized by something other than its lo and hi values) as well as outward rounding for ThickNumber types that aim to be conservative and guarantee acccuracy even in the presence of roundoff error.
If your ThickNumber subtype can't be constructed this way, you will likely have to specialize several of the ThickNumber API functions to compensate.
You also need to implement any binary arithmetic operations (a + b, a - b, a * b, a / b). Unary + and - (i.e., -x) have default implementations for all ThickNumber subtypes, although you can choose to specialize if warranted.