# Few questions on usage of (convert) and (promote) in dual.jl

**URL:** <https://discourse.julialang.org/t/few-questions-on-usage-of-convert-and-promote-in-dual-jl/56210>\
**Category:** New to Julia\
**Created:** [February 28, 2021, 8:16pm UTC](https://discourse.julialang.org/t/few-questions-on-usage-of-convert-and-promote-in-dual-jl/56210 "2021-02-28T20:16:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asyrov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asyrov/32/13578_2.png) [@asyrov](https://discourse.julialang.org/u/asyrov)\
**Post date:** [February 28, 2021, 8:16pm UTC](https://discourse.julialang.org/t/few-questions-on-usage-of-convert-and-promote-in-dual-jl/56210/1 "2021-02-28T20:16:44Z")

</div>

I’m looking at [conversion-and-promotion](https://docs.julialang.org/en/v1/manual/conversion-and-promotion/) documentation and also [dual.jl](https://github.com/JuliaDiff/DualNumbers.jl/blob/master/src/dual.jl) implementation and need help the following lines. (I apologize that I’m asking several questions in the same topic).

Unclear, why we need the following conversion. Not clear what else could it be and then why we need it:

```julia
Base.convert(::Type{Dual{T}}, z::Dual{T}) where {T<:ReComp} = z

```

Following is also not clear. I thought that Dual by itself is not a type, so why is this not something like Dual{S} (or is there difference between Dual and Dual{S})?

```julia
Base.convert(::Type{Dual{T}}, z::Dual) where {T<:ReComp} = Dual{T}(convert(T, value(z)), convert(T, epsilon(z)))

```

So we define promote\_rules for for a Number to become Dual, but why then we define addition between Number and Dual. Is this for better performance?

```julia
Base.:+(z::Dual, w::Dual) = Dual(value(z)+value(w), epsilon(z)+epsilon(w))
Base.:+(z::Number, w::Dual) = Dual(z+value(w), epsilon(w))
Base.:+(z::Dual, w::Number) = Dual(value(z)+w, epsilon(z))

```

Thank you very much in advance for helping.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 1, 2021, 9:41am UTC](https://discourse.julialang.org/t/few-questions-on-usage-of-convert-and-promote-in-dual-jl/56210/2 "2021-03-01T09:41:40Z")

</div>

> [@asyrov](#):
>
> Not clear what else could it be and then why we need it

I think it is a fallback for the no-op, otherwise the other methods would kick in.

> [@asyrov](#):
>
> I thought that Dual by itself is not a type

It is a `UnionAll` type, see

[https://docs.julialang.org/en/v1.7-dev/manual/types/#UnionAll-Types](https://docs.julialang.org/en/v1.7-dev/manual/types/#UnionAll-Types)
