Skip to content

Commit

Permalink
Add constructor calling convert for (::Type{<:Dual})(::Real), fix #336 (
Browse files Browse the repository at this point in the history
  • Loading branch information
schmrlng authored and jrevels committed Jul 27, 2018
1 parent 123cc19 commit 9fe228c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ end
Base.convert(::Type{Dual{T,V,N}}, d::Dual{T}) where {T,V<:Real,N} = Dual{T}(convert(V, value(d)), convert(Partials{N,V}, partials(d)))
Base.convert(::Type{Dual{T,V,N}}, x::Real) where {T,V<:Real,N} = Dual{T}(convert(V, x), zero(Partials{N,V}))
Base.convert(::Type{D}, d::D) where {D<:Dual} = d
(::Type{D})(x::Real) where {D<:Dual} = convert(D, x)

Base.float(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, Float16),N}, d)
Base.AbstractFloat(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, Float16),N}, d)
Expand Down

0 comments on commit 9fe228c

Please sign in to comment.