Skip to content

Commit 3079ca1

Browse files
authored
Merge pull request #444 from matbesancon/fix-typemin
add typemax typemin
2 parents 7f9b9b7 + 095b537 commit 3079ca1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/dual.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ end
8686
if S T
8787
d
8888
else
89-
throw(DualMismatchError(T,S))
89+
throw(DualMismatchError(T,S))
9090
end
9191
end
9292

@@ -612,3 +612,11 @@ function Base.show(io::IO, d::Dual{T,V,N}) where {T,V,N}
612612
end
613613
print(io, ")")
614614
end
615+
616+
function Base.typemin(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N}
617+
ForwardDiff.Dual{T,V,N}(typemin(V))
618+
end
619+
620+
function Base.typemax(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N}
621+
ForwardDiff.Dual{T,V,N}(typemax(V))
622+
end

test/DualTest.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,15 @@ end
476476
@test pow(x1, 0) === x1^0 === Dual{:t1}(1.0, 0.0)
477477
end
478478

479+
@testset "Type min/max" begin
480+
d1 = Dual(1.0)
481+
dinf = typemax(typeof(d1))
482+
dminf = typemin(typeof(d1))
483+
@test dminf < d1 < dinf
484+
@test typeof(dminf) === typeof(d1)
485+
@test typeof(dinf) === typeof(d1)
486+
@test !isfinite(dminf)
487+
@test !isfinite(dinf)
488+
end
489+
479490
end # module

0 commit comments

Comments
 (0)