Skip to content

Commit 9fe228c

Browse files
schmrlngjrevels
authored andcommitted
Add constructor calling convert for (::Type{<:Dual})(::Real), fix #336 (#337)
1 parent 123cc19 commit 9fe228c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/dual.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ end
315315
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)))
316316
Base.convert(::Type{Dual{T,V,N}}, x::Real) where {T,V<:Real,N} = Dual{T}(convert(V, x), zero(Partials{N,V}))
317317
Base.convert(::Type{D}, d::D) where {D<:Dual} = d
318+
(::Type{D})(x::Real) where {D<:Dual} = convert(D, x)
318319

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

0 commit comments

Comments
 (0)