diff --git a/src/dual.jl b/src/dual.jl index d66a826c..c8bb4361 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -86,7 +86,7 @@ end if S ≺ T d else - throw(DualMismatchError(T,S)) + throw(DualMismatchError(T,S)) end end @@ -612,3 +612,11 @@ function Base.show(io::IO, d::Dual{T,V,N}) where {T,V,N} end print(io, ")") end + +function Base.typemin(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N} + ForwardDiff.Dual{T,V,N}(typemin(V)) +end + +function Base.typemax(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N} + ForwardDiff.Dual{T,V,N}(typemax(V)) +end diff --git a/test/DualTest.jl b/test/DualTest.jl index a892c7f7..dec58c1f 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -476,4 +476,15 @@ end @test pow(x1, 0) === x1^0 === Dual{:t1}(1.0, 0.0) end +@testset "Type min/max" begin + d1 = Dual(1.0) + dinf = typemax(typeof(d1)) + dminf = typemin(typeof(d1)) + @test dminf < d1 < dinf + @test typeof(dminf) === typeof(d1) + @test typeof(dinf) === typeof(d1) + @test !isfinite(dminf) + @test !isfinite(dinf) +end + end # module