Creating a new ThickNumber subtype
For a concrete example, see the ThickNumbersInterfaceTests/test/testpackages/IntervalArith
"package" in the main source repository of ThickNumbers.jl
. You can get a hint of the behaviors this endows by looking at ThickNumbers/test/runtests.jl
, which uses the Interval
type defined by IntervalArith
.
Create your type by subtyping ThickNumber{T}
:
struct MyType{T<:Real} <: ThickNumber{T}
# you can have whatever fields you need...
a::T
b::T
end
If you only intend to support, say, Float64
, you can use struct MyType <: ThickNumber{Float64} ... end
: the key point is that the T
in ThickNumber{T}
should encode the valuetype
.
The following interface functions must be defined:
loval(x)
: should return the lower span (i.e., the "lower bound" if such bounds are strict).hival(x)
: should return the upper span.basetype(x)
: should strip thevaluetype
, i.e.,basetype(Interval{Float64})
returnsInterval
.- any arithmetic operations you need, e.g.,
+
,-
,*
, and/
The implementation of these functions must satisfy certain requirements spelled out in the documentation of each of these functions.
If possible, you should also define:
lohi(MyType{T}, lo, hi)
: constructx
from two numbers specifying the lower and upper spans.
If you cannot define this for your type (e.g., MyType
requires more than two arguments to construct), it is likely that you'll have to specialize some of the User API functions for MyType
, since the default implementations of some of them rely on lohi
.
There are also numerous optional methods you can specialize if it makes MyType
operate more efficiently. For example, a gaussian random variable package might want to implement midrad(MyType{T}, center, σ)
to construct values directly, assuming this is the natural parametrization of this type.
Ensuring compliance with the ThickNumbers interface
The ThickNumbersInterfaceTests
package can be used to determine whether your implementations comply with the requirements. As it is possible that this test suite will evolve and add new requirements, be sure to use [compat]
bounds to specify the major version number of ThickNumbersInterfaceTests
that your implementation satisfies.
Features provided by subtyping ThickNumber
See the User API.