From 78f230f0a3c2c965529120418f037b2ca39f017a Mon Sep 17 00:00:00 2001 From: Matthieu Ancellin <31126826+mancellin@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:19:22 +0200 Subject: [PATCH] Add support for floatmax(value) and friends --- src/dual.jl | 3 +++ test/DualTest.jl | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/dual.jl b/src/dual.jl index 7e8ec110..3f105640 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -830,6 +830,9 @@ function Base.show(io::IO, d::Dual{T,V,N}) where {T,V,N} end for op in (:(Base.typemin), :(Base.typemax), :(Base.floatmin), :(Base.floatmax)) + @eval function $op(::ForwardDiff.Dual{T,V,N}) where {T,V,N} + ForwardDiff.Dual{T,V,N}($op(V)) + end @eval function $op(::Type{ForwardDiff.Dual{T,V,N}}) where {T,V,N} ForwardDiff.Dual{T,V,N}($op(V)) end diff --git a/test/DualTest.jl b/test/DualTest.jl index 6d0bf85f..e35680b4 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -638,6 +638,12 @@ end @test isfinite(dfmin) @test isfinite(dfmax) + # Functions can be called with type or value + @test typemin(d1) == typemin(typeof(d1)) + @test typemax(d1) == typemax(typeof(d1)) + @test floatmin(d1) == floatmin(typeof(d1)) + @test floatmax(d1) == floatmax(typeof(d1)) + @test floatmin(Dual{Nothing, ForwardDiff.Dual{Nothing, Float64, 2}, 1}) === Dual{Nothing}(Dual{Nothing}(floatmin(Float64),0.0,0.0),Dual{Nothing}(0.0,0.0,0.0)) end