Skip to content

Commit

Permalink
Fix method ambiguity for Base.TwicePrecision
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Oct 29, 2024
1 parent ec74fbc commit 37786e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ end
@inline Dual{T,V,N}(x::Number) where {T,V,N} = convert(Dual{T,V,N}, x)
@inline Dual{T,V}(x) where {T,V} = convert(Dual{T,V}, x)

# Fix method ambiguity issue by adapting the definition in Base to `Dual`s
Dual{T,V,N}(x::Base.TwicePrecision) where {T,V,N} =
(Dual{T,V,N}(x.hi) + Dual{T,V,N}(x.lo))::Dual{T,V,N}

##############################
# Utility/Accessor Functions #
##############################
Expand Down
4 changes: 4 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,8 @@ end
@test ForwardDiff.derivative(float, 1)::Float64 === 1.0
end

@testset "TwicePrecision" begin
@test ForwardDiff.derivative(x -> sum(1 .+ x .* (0:0.1:1)), 1) == 5.5
end

end # module

0 comments on commit 37786e5

Please sign in to comment.