How can I add types that are integers and pass them along to other parameterized types?
e.g.,
const PointRpN{N <: Integer, T <: AbstractFloat} = Euclidean.PointNd{N+1,T}
const PointRp2{T <: AbstractFloat} = PointRpN{2,T}
How can I add types that are integers and pass them along to other parameterized types?
e.g.,
const PointRpN{N <: Integer, T <: AbstractFloat} = Euclidean.PointNd{N+1,T}
const PointRp2{T <: AbstractFloat} = PointRpN{2,T}
abstract type MyNum end
struct MyInt{T<:Integer} <: MyNum
int::T
end
value(x::MyInt) = x.int
MyInt(x::AbstractFloat) = MyInt(trunc(Int, x))
struct MyFloat{T<:AbstractFloat} <: MyNum
float::T
end
value(x::MyFloat) = x.float
MyFloat(x::Integer) = MyFloat(float(x))
Base.:(+)(a::MyInt, b::MyInt) = MyInt(a.int + b.int)
Base.:(+)(a::MyFloat, b::MyFloat) = MyFloat(a.float + b.float)
Base.:(+)(a::MyNum, b::MyNum) = MyFloat(value(a) + value(b))
now
julia> int1 = MyInt(7)
MyInt{Int64}(7)
julia> int2 = MyInt(16.0)
MyInt{Int64}(16)
julia> flt1 = MyFloat(7)
MyFloat{Float64}(7.0)
julia> flt2 = MyFloat(Float32(16))
MyFloat{Float32}(16.0f0)
julia> int1 + int2
MyInt{Int64}(23)
julia> flt1 + flt2
MyFloat{Float64}(23.0)
julia> int1 + flt1
MyFloat{Float64}(14.0)