# Arithmetic with types

**URL:** https://discourse.julialang.org/t/arithmetic-with-types/88278
**Category:** General Usage
**Tags:** question
**Created:** [October 5, 2022, 9:03am UTC](https://discourse.julialang.org/t/arithmetic-with-types/88278 "2022-10-05T09:03:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)
#### Post date: [October 5, 2022, 9:03am UTC](https://discourse.julialang.org/t/arithmetic-with-types/88278/1 "2022-10-05T09:03:06Z")

</div>

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}

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [October 5, 2022, 10:06am UTC](https://discourse.julialang.org/t/arithmetic-with-types/88278/2 "2022-10-05T10:06:41Z")

</div>

```julia
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

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)

```
