Skip to content

Commit

Permalink
Fix InexactError call in convert (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Aug 18, 2023
1 parent 9a89867 commit d9251a7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DualNumbers"
uuid = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
version = "0.6.8"
version = "0.6.9"

[deps]
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
Expand Down
2 changes: 1 addition & 1 deletion src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DualComplex64 = Dual{ComplexF16}
Base.convert(::Type{Dual{T}}, z::Dual{T}) where {T<:ReComp} = z
Base.convert(::Type{Dual{T}}, z::Dual) where {T<:ReComp} = Dual{T}(convert(T, value(z)), convert(T, epsilon(z)))
Base.convert(::Type{Dual{T}}, x::Number) where {T<:ReComp} = Dual{T}(convert(T, x), convert(T, 0))
Base.convert(::Type{T}, z::Dual) where {T<:ReComp} = (epsilon(z)==0 ? convert(T, value(z)) : throw(InexactError()))
Base.convert(::Type{T}, z::Dual) where {T<:ReComp} = (epsilon(z)==0 ? convert(T, value(z)) : throw(InexactError(:convert, T, z)))

Base.promote_rule(::Type{Dual{T}}, ::Type{Dual{S}}) where {T<:ReComp,S<:ReComp} = Dual{promote_type(T, S)}
Base.promote_rule(::Type{Dual{T}}, ::Type{S}) where {T<:ReComp,S<:ReComp} = Dual{promote_type(T, S)}
Expand Down
2 changes: 2 additions & 0 deletions test/automatic_differentiation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,5 @@ end

@test value(3) == 3
@test epsilon(44.0) 0.0

@test_throws InexactError convert(Float64, Dual(1,1))

0 comments on commit d9251a7

Please sign in to comment.