Skip to content

Commit 80a13d9

Browse files
authored
Overload floatmin, floatmax (#525)
1 parent 27e1a8d commit 80a13d9

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/dual.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,10 @@ function Base.show(io::IO, d::Dual{T,V,N}) where {T,V,N}
691691
print(io, ")")
692692
end
693693

694-
function Base.typemin(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N}
695-
ForwardDiff.Dual{T,V,N}(typemin(V))
696-
end
697-
698-
function Base.typemax(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N}
699-
ForwardDiff.Dual{T,V,N}(typemax(V))
694+
for op in (:(Base.typemin), :(Base.typemax), :(Base.floatmin), :(Base.floatmax))
695+
@eval function $op(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N}
696+
ForwardDiff.Dual{T,V,N}($op(V))
697+
end
700698
end
701699

702700
if VERSION >= v"1.6.0-rc1"

test/DualTest.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ end
503503
@test typeof(dinf) === typeof(d1)
504504
@test !isfinite(dminf)
505505
@test !isfinite(dinf)
506+
507+
dfmin = floatmin(typeof(d1))
508+
dfmax = floatmax(typeof(d1))
509+
@test dfmin < d1 < dfmax
510+
@test typeof(dfmin) === typeof(d1)
511+
@test typeof(dfmax) === typeof(d1)
512+
@test isfinite(dfmin)
513+
@test isfinite(dfmax)
506514
end
507515

508516
@testset "Integer" begin

0 commit comments

Comments
 (0)