Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ForwardDiff"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.19"
version = "0.10.20"

[deps]
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
Expand Down
4 changes: 4 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ end
Integer(value(d))
end

for F in (:Float16, :Float32, :Float64)
@eval @inline Base.$F(d::Dual{T,V,N}) where {T,V,N} = convert(Dual{T,promote_type(V, $F),N}, d)
end

@inline Random.rand(rng::AbstractRNG, d::Dual) = rand(rng, value(d))
@inline Random.rand(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(V), zero(Partials{N,V}))
@inline Random.rand(rng::AbstractRNG, ::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T}(rand(rng, V), zero(Partials{N,V}))
Expand Down
6 changes: 6 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ end
@test length(UnitRange(Dual(1.5), Dual(3.5))) == 3
@test length(UnitRange(Dual(1.5,1), Dual(3.5,3))) == 3
end

@testset "Float" begin
for F in (Float16, Float32, Float64)
@test F(Dual(3, 5)) == Dual(F(3), F(5))
end
end

if VERSION >= v"1.6.0-rc1"
@testset "@printf" begin
Expand Down